Merge pull request #790 from mykmelez/file-connection-tests

add FileConnection tests and fix various correctness issues
This commit is contained in:
Marco 2014-12-30 02:14:00 +01:00
Родитель 14e138d2f9 323e64bdc6
Коммит 017fb2bd12
65 изменённых файлов: 14455 добавлений и 94 удалений

31
LICENSE
Просмотреть файл

@ -199,6 +199,37 @@ The SOFTWARE this license applies to is the Java Specification Request (JSR) 075
---
JSR -075 Technology Compatibility Kit License Agreement
BY DOWNLOADING OR USING THE SOFTWARE AND/OR DOCUMENTATION DESCRIBED IN EXHIBIT A HERETO (COLLECTIVELY THE SOFTWARE), YOU AGREE TO THE FOLLOWING TERMS AND CONDITIONS (AGREEMENT). IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT, YOU MAY NOT DOWNLOAD OR USE THE SOFTWARE.
License Grant. You are hereby granted a personal, non-transferable and non-sublicenseable, nonexclusive, world-wide, royalty free license to use the JSR-075 Technology Compatibility Kit (including software and documentation) (the TCK) solely for the purpose of testing compliance with the relevant portions of specifications or standards to which it applies (the Specification). You may not modify or create derivative works of any of the TCK except as is necessary to fulfill the purpose described above. You may not distribute copies of the TCK to other parties for any purpose, including for the purpose of allowing such other party to use the TCK. Nor may you modify or incorporate the TCK into any other software.
No Warranties. The TCK contained herein is provided on an "AS IS" basis and to the maximum extent permitted by applicable law, this material is provided AS IS AND WITH ALL FAULTS, and the developers of this material hereby disclaim all other warranties and conditions, either express, implied or statutory, including, but not limited to, any (if any) implied warranties, duties or conditions of merchantability, of fitness for a particular purpose, of accuracy or completeness of responses, of results, of workmanlike effort, of lack of viruses, and of lack of negligence. ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT WITH REGARD TO THIS MATERIAL.
Limitation of Liability. IN NO EVENT WILL ANY AUTHOR, DEVELOPER, LICENSOR, OR DISTRIBUTOR OF THIS MATERIAL BE LIABLE TO ANY OTHER PARTY FOR THE COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, INDIRECT, PUNITIVE, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT RELATING TO THIS MATERIAL, WHETHER OR NOT SUCH PARTY HAD ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.
Covenant Not to Assert. As a material condition to this license you hereby agree, to the extent that you have any patents which cover the use of the TCK in any manner permitted under this License, not to assert any such patents against the developers or distributors of the TCK or any other parties who have entered into a license substantially similar to this License for the licensed use of the TCK.
Reciprocity. You may have, or may have in the future, the ability to license test suites developed or distributed pursuant to the Java Community Process ("Java Materials"). You acknowledge that under this license you are receiving the TCK under reasonable royalty-free terms. While you are not obligated to make Java Materials available, if you do so, you agree to license them under reasonable royalty-free terms. For the purpose of this paragraph, terms are not reasonable terms if they are more restrictive than this license or if they discriminate against any individual or group of JCP members or against implementers of independent implementations or open source implementations. If you do make Java Materials available in the future and do not license such Java Materials under reasonable royalty-free terms, as consideration for licensing this TCK to you, you agree to pay IBM royalties as follows: (a) Thirty Thousand Dollars ($30,000) payable within thirty (30) days of your distribution of such Java Materials and (b) an additional Ten Thousand Dollars ($10,000) per year for each year you use this TCK or use and/or distribute a product that has been tested for compliance with this TCK. In no event shall royalties in the aggregate exceed Sixty Thousand Dollars ($60,000.) IBM will notify you in writing how to make such royalty payments
Compatibility Claims. You may not claim that any version or release of software passes the TCK, and therefore is compatible with the Specification, unless it is capable of passing the most current version of the TCK available 120 days prior to the date of its first shipment to customers. You will make available information regarding the version of the TCK passed, upon request. You agree that any claims regarding compliance with the Specification will be factually accurate and will not be misleading.
General.
No other rights are granted by implication, estoppel or otherwise.
If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
Your rights under this Agreement shall terminate if you fail to comply with any of the material terms or conditions of this Agreement and do not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If your rights under this Agreement terminate, you agree to cease use of the TCK immediately and cease making any claims of compatibility regarding the Specification based on the use of the TCK.
This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
EXHIBIT A
The SOFTWARE this license applies to is the Java Specification Request (JSR) 075 for the Personal Information Manager and the File Connection optional package Technology Compatibility Kits (TCK).
---
libs/rusha.js: The MIT License (MIT)
Copyright (c) 2013-2014 Sam Rijs

Просмотреть файл

@ -26,7 +26,7 @@ import com.sun.midp.log.*;
public class Connection implements FileConnection, CreateConnection {
/* The url string that was sent to Connector.open(),
* without the preceeding "://" and host name.
* without the preceeding "://", host name, and leading "/".
* file separator is "/".
*/
private String fullPath;
@ -42,6 +42,12 @@ public class Connection implements FileConnection, CreateConnection {
private byte[] properPath;
private String host;
// The name of the "filesystem root".
// WARNING! This is not what you would expect if you have a Unix
// background. It isn't "/", the "root directory" in a filesystem.
// Rather, it's the "first directory in the file URI", as described
// by FileSystemRegistry.java. For example, "SDCard/".
private String root;
/* The directory containing this file or dir.
@ -843,7 +849,7 @@ private String validateSpec(String spec) {
if (idx==0) {
// no host is specified, since the URL started as "file:///"
host="";
fullPath=spec.substring(0,spec.length()) ;
fullPath=spec.substring(1,spec.length()) ;
} else {
// There is a host specified
// make sure it is a valid specification.
@ -853,7 +859,7 @@ private String validateSpec(String spec) {
if ((idx2!=-1 && idx2<idx ) || (idx3!=-1 && idx3<idx ))
throw new IllegalArgumentException(spec);
fullPath = spec.substring(idx,spec.length());
fullPath = spec.substring(idx+1,spec.length());
host = spec.substring(0,idx);
}

Просмотреть файл

@ -5,8 +5,14 @@
// Directories in the filesystem.
var initialDirs = [
"/MemoryCard",
"/Persistent",
"/Photos",
"/Phone",
"/Phone/_my_downloads",
"/Phone/_my_pictures",
"/Phone/_my_videos",
"/Phone/_my_recordings",
"/Private",
];
// Files in the filesystem. We load the data from the source path on the real
@ -19,15 +25,21 @@ var initialFiles = [
var initFS = new Promise(function(resolve, reject) {
fs.init(resolve);
}).then(function() {
var dirPromises = [];
if (typeof MIDP !== "undefined" && MIDP.midletClassName == "RunTests") {
initialDirs.push("/tcktestdir");
}
initialDirs.forEach(function(dir) {
dirPromises.push(new Promise(function(resolve, reject) {
fs.mkdir(dir, resolve);
}));
});
return Promise.all(dirPromises);
// Create directories sequentially so parents exist before children
// are created. We could use fs.mkdirp instead, but it won't necessarily
// be faster, since it'll still create parents before children, and each
// child's creation will trigger existence checks on all parent dirs.
return initialDirs.reduce(function(current, next) {
return current.then(function() {
return new Promise(function(resolve, reject) {
fs.mkdir(next, resolve);
});
});
}, Promise.resolve());
}).then(function() {
var filePromises = [];

Просмотреть файл

@ -681,7 +681,8 @@ var fs = (function() {
store.getItem(path, function(record) {
if (!record) {
cb(true);
// If the path doesn't exist, then we can't remove it.
cb(false);
} else if (record.isDir) {
// If the directory isn't empty, then we can't remove it.
store.isEmpty(path, function(empty) {

Просмотреть файл

@ -5,6 +5,25 @@
var RECORD_STORE_BASE = "/RecordStore";
// The filesystem roots, which are used by both FileSystemRegistry.getRootsImpl
// and System.getProperty to provide inquiring midlets with the list. Each root
// must have a trailing slash. See FileSystemRegistry.listRoots for more info.
MIDP.fsRoots = [
"MemoryCard/",
"Phone/",
"Private/",
];
// The names here should be localized.
MIDP.fsRootNames = [
"Memory card",
"Phone memory",
"Private",
];
function getAbsolutePath(jPath) {
return "/" + util.decodeUtf8(jPath);
}
Native.create("com/sun/midp/io/j2me/storage/File.initConfigRoot.(I)Ljava/lang/String;", function(storageId) {
return "assets/" + storageId + "/";
});
@ -267,20 +286,36 @@ Override.create("com/ibm/oti/connection/file/Connection.encode.(Ljava/lang/Strin
return util.fromJavaString(string).replace(/[^a-zA-Z0-9-_\.!~\*\\'()/:]/g, encodeURIComponent);
});
Native.create("com/ibm/oti/connection/file/Connection.availableSizeImpl.([B)J", function(path) {
Native.create("com/ibm/oti/connection/file/Connection.totalSizeImpl.([B)J", function(root) {
console.warn("Connection.totalSizeImpl.([B)J not implemented (" + util.decodeUtf8(root) + ")");
return Long.fromNumber(-1);
});
Native.create("com/ibm/oti/connection/file/Connection.usedSizeImpl.([B)J", function(root) {
console.warn("Connection.usedSizeImpl.([B)J not implemented (" + util.decodeUtf8(root) + ")");
return Long.fromNumber(-1);
});
Native.create("com/ibm/oti/connection/file/Connection.availableSizeImpl.([B)J", function(root) {
console.warn("Connection.availableSizeImpl.([B)J not implemented (" + util.decodeUtf8(root) + ")");
// Pretend there is 1 GB available
return Long.fromNumber(1024 * 1024 * 1024);
});
Native.create("com/ibm/oti/connection/file/Connection.existsImpl.([B)Z", function(path) {
return new Promise(function(resolve, reject) {
fs.exists(util.decodeUtf8(path), resolve);
fs.exists(getAbsolutePath(path), resolve);
});
}, true);
Native.create("com/ibm/oti/connection/file/Connection.directorySizeImpl.([BZ)J", function(path, includeSubDirs) {
console.warn("Connection.directorySizeImpl.([BZ)J not implemented (" + getAbsolutePath(path) + ", " + includeSubDirs + ")");
return Long.fromNumber(0);
});
Native.create("com/ibm/oti/connection/file/Connection.fileSizeImpl.([B)J", function(path) {
return new Promise(function(resolve, reject) {
fs.size(util.decodeUtf8(path), function(size) {
fs.size(getAbsolutePath(path), function(size) {
resolve(Long.fromNumber(size));
});
});
@ -288,7 +323,7 @@ Native.create("com/ibm/oti/connection/file/Connection.fileSizeImpl.([B)J", funct
Native.create("com/ibm/oti/connection/file/Connection.isDirectoryImpl.([B)Z", function(path) {
return new Promise(function(resolve, reject) {
fs.stat(util.decodeUtf8(path), function(stat) {
fs.stat(getAbsolutePath(path), function(stat) {
resolve(!!stat && stat.isDir);
});
});
@ -296,7 +331,7 @@ Native.create("com/ibm/oti/connection/file/Connection.isDirectoryImpl.([B)Z", fu
Native.create("com/ibm/oti/connection/file/Connection.listImpl.([B[BZ)[[B",
function(jPath, filterArray, includeHidden) {
var path = util.decodeUtf8(jPath);
var path = getAbsolutePath(jPath);
return new Promise(function(resolve, reject) {
var filter = "";
if (filterArray) {
@ -312,9 +347,10 @@ function(jPath, filterArray, includeHidden) {
filter = filter.replace(/([.+^${}()|\[\]\/\\])/g, "\\$1");
// Transform * to .+
filter = filter.replace(/\*/g, ".+");
filter = filter.replace(/\*/g, ".*");
filter += "$";
// Require filter to match from the beginning to the end.
filter = "^" + filter + "$";
}
fs.list(path, function(error, files) {
@ -348,7 +384,7 @@ function(jPath, filterArray, includeHidden) {
Native.create("com/ibm/oti/connection/file/Connection.mkdirImpl.([B)I", function(path) {
return new Promise(function(resolve, reject) {
fs.mkdir(util.decodeUtf8(path), function(created) {
fs.mkdir(getAbsolutePath(path), function(created) {
// IBM's implementation returns different error numbers, we don't care
resolve(created ? 0 : 42);
});
@ -356,16 +392,12 @@ Native.create("com/ibm/oti/connection/file/Connection.mkdirImpl.([B)I", function
}, true);
Native.create("com/ibm/oti/connection/file/Connection.newFileImpl.([B)I", function(jPath) {
var path = util.decodeUtf8(jPath);
var path = getAbsolutePath(jPath);
return new Promise(function(resolve, reject) {
// IBM's implementation returns different error numbers, we don't care
fs.exists(path, function(exists) {
if (exists) {
fs.truncate(path, function(truncated) {
resolve(truncated ? 0 : 42);
});
fs.stat(path, function(stat) {
if (stat !== null) {
resolve(stat.isDir ? 3 : 1);
} else {
fs.create(path, new Blob(), function(created) {
resolve(created ? 0 : 42);
@ -377,7 +409,7 @@ Native.create("com/ibm/oti/connection/file/Connection.newFileImpl.([B)I", functi
Native.create("com/ibm/oti/connection/file/Connection.deleteFileImpl.([B)Z", function(path) {
return new Promise(function(resolve, reject) {
fs.remove(util.decodeUtf8(path), resolve);
fs.remove(getAbsolutePath(path), resolve);
});
}, true);
@ -385,18 +417,18 @@ Native["com/ibm/oti/connection/file/Connection.deleteDirImpl.([B)Z"] =
Native["com/ibm/oti/connection/file/Connection.deleteFileImpl.([B)Z"]
Native.create("com/ibm/oti/connection/file/Connection.isReadOnlyImpl.([B)Z", function(path) {
console.warn("Connection.isReadOnlyImpl.([B)Z not implemented (" + util.decodeUtf8(path) + ")");
console.warn("Connection.isReadOnlyImpl.([B)Z not implemented (" + getAbsolutePath(path) + ")");
return false;
});
Native.create("com/ibm/oti/connection/file/Connection.isWriteOnlyImpl.([B)Z", function(path) {
console.warn("Connection.isWriteOnlyImpl.([B)Z not implemented (" + util.decodeUtf8(path) + ")");
console.warn("Connection.isWriteOnlyImpl.([B)Z not implemented (" + getAbsolutePath(path) + ")");
return false;
});
Native.create("com/ibm/oti/connection/file/Connection.lastModifiedImpl.([B)J", function(path) {
return new Promise(function(resolve, reject) {
fs.stat(util.decodeUtf8(path), function(stat) {
fs.stat(getAbsolutePath(path), function(stat) {
resolve(Long.fromNumber(stat != null ? stat.mtime : 0));
});
});
@ -404,7 +436,7 @@ Native.create("com/ibm/oti/connection/file/Connection.lastModifiedImpl.([B)J", f
Native.create("com/ibm/oti/connection/file/Connection.renameImpl.([B[B)V", function(oldPath, newPath) {
return new Promise(function(resolve, reject) {
fs.rename(util.decodeUtf8(oldPath), util.decodeUtf8(newPath), function(renamed) {
fs.rename(getAbsolutePath(oldPath), getAbsolutePath(newPath), function(renamed) {
if (!renamed) {
reject(new JavaException("java/io/IOException", "Rename failed"));
return;
@ -417,7 +449,7 @@ Native.create("com/ibm/oti/connection/file/Connection.renameImpl.([B[B)V", funct
Native.create("com/ibm/oti/connection/file/Connection.truncateImpl.([BJ)V", function(path, newLength, _) {
return new Promise(function(resolve, reject) {
fs.open(util.decodeUtf8(path), function(fd) {
fs.open(getAbsolutePath(path), function(fd) {
if (fd == -1) {
reject(new JavaException("java/io/IOException", "truncate failed"));
return;
@ -432,7 +464,7 @@ Native.create("com/ibm/oti/connection/file/Connection.truncateImpl.([BJ)V", func
Native.create("com/ibm/oti/connection/file/FCInputStream.openImpl.([B)I", function(path) {
return new Promise(function(resolve, reject) {
fs.open(util.decodeUtf8(path), resolve);
fs.open(getAbsolutePath(path), resolve);
});
}, true);
@ -487,7 +519,7 @@ Native.create("com/ibm/oti/connection/file/FCOutputStream.closeImpl.(I)V", funct
});
Native.create("com/ibm/oti/connection/file/FCOutputStream.openImpl.([B)I", function(jPath) {
var path = util.decodeUtf8(jPath);
var path = getAbsolutePath(jPath);
return new Promise(function(resolve, reject) {
fs.exists(path, function(exists) {
@ -512,7 +544,7 @@ Native.create("com/ibm/oti/connection/file/FCOutputStream.openImpl.([B)I", funct
}, true);
Native.create("com/ibm/oti/connection/file/FCOutputStream.openOffsetImpl.([BJ)I", function(jPath, offset, _) {
var path = util.decodeUtf8(jPath);
var path = getAbsolutePath(jPath);
return new Promise(function(resolve, reject) {
function open() {
@ -629,8 +661,16 @@ Native.create("com/sun/midp/io/j2me/storage/RandomAccessStream.close.(I)V", func
fs.close(handle);
});
Native.create("javax/microedition/io/file/FileSystemRegistry.initImpl.()V", function() {
console.warn("javax/microedition/io/file/FileSystemRegistry.initImpl.()V not implemented");
});
Native.create("javax/microedition/io/file/FileSystemRegistry.getRootsImpl.()[Ljava/lang/String;", function() {
var array = util.newArray("[Ljava/lang/String;", 1);
array[0] = util.newString("");
var array = util.newArray("[Ljava/lang/String;", MIDP.fsRoots.length);
for (var i = 0; i < MIDP.fsRoots.length; i++) {
array[i] = util.newString(MIDP.fsRoots[i]);
}
return array;
});

Просмотреть файл

@ -62,6 +62,9 @@ Native.create("java/lang/System.getProperty0.(Ljava/lang/String;)Ljava/lang/Stri
// UTF_8_Writer and optimize the ISO8859_1 alternatives.
value = "UTF-8";
break;
case "microedition.io.file.FileConnection.version":
value = "1.0";
break;
case "microedition.locale":
value = navigator.language;
break;
@ -87,36 +90,51 @@ Native.create("java/lang/System.getProperty0.(Ljava/lang/String;)Ljava/lang/Stri
value = null;
break;
case "fileconn.dir.memorycard":
value = "file:///";
value = "file:///MemoryCard/";
break;
// The names here should be localized.
case "fileconn.dir.memorycard.name":
value = "Memory card";
break;
case "fileconn.dir.private":
value = "file:///";
value = "file:///Private/";
break;
case "fileconn.dir.private.name":
value = "Private";
break;
case "fileconn.dir.applications.bookmarks":
value = "file:///";
value = null;
break;
case "fileconn.dir.received":
value = "file:///";
value = "file:///Phone/_my_downloads/";
break;
case "fileconn.dir.received.name":
value = "Downloads";
break;
case "fileconn.dir.photos":
value = "file:///Photos/";
break;
case "fileconn.dir.roots.names":
// The names here should be localized.
value = "Memory card;Phone memory;Private"
break;
case "fileconn.dir.roots.external":
value = "file:///MemoryCard;file:///;file:///";
value = "file:///Phone/_my_pictures/";
break;
case "fileconn.dir.photos.name":
value = "Photos";
break;
case "fileconn.dir.videos":
value = "file:///Phone/_my_videos/";
break;
case "fileconn.dir.videos.name":
value = "Videos";
break;
case "fileconn.dir.recordings":
value = "file:///Phone/_my_recordings/";
break;
case "fileconn.dir.recordings.name":
value = "Recordings";
break;
case "fileconn.dir.roots.names":
value = MIDP.fsRootNames.join(";");
break;
case "fileconn.dir.roots.external":
value = MIDP.fsRoots.map(function(v) { return "file:///" + v }).join("\n");
break;
case "file.separator":
value = "/";
break;

Просмотреть файл

@ -62,7 +62,7 @@ var gfxTests = [
];
var expectedUnitTestResults = [
{ name: "pass", number: 71535 },
{ name: "pass", number: 71538 },
{ name: "fail", number: 0 },
{ name: "known fail", number: 180 },
{ name: "unknown pass", number: 0 }
@ -102,7 +102,7 @@ casper.test.begin("unit tests", 11 + gfxTests.length, function(test) {
casper
.thenOpen("http://localhost:8000/tests/fs/test-fs-init.html")
.waitForText("DONE", function() {
test.assertTextExists("DONE: 14 PASS, 0 FAIL", "test fs init");
test.assertTextExists("DONE: 30 pass, 0 fail", "test fs init");
});
function basicUnitTests() {

Просмотреть файл

@ -35,6 +35,7 @@ public class TestFileConnection implements Testlet {
Enumeration files = dir.list("*.doc", false);
th.check(files.hasMoreElements(), "Elements found");
expected.put(".doc", "");
expected.put("prova1.doc", "");
expected.put("prova2.doc", "");
expected.put("prova3.doc", "");
@ -217,7 +218,7 @@ public class TestFileConnection implements Testlet {
file.list();
th.fail("Exception expected");
} catch (IOException e) {
th.check(e.getMessage(), "Directory does not exist: file:////provaDir/prova");
th.check(e.getMessage(), "Directory does not exist: file:///Private/provaDir/prova");
}
file.create();
@ -230,7 +231,7 @@ public class TestFileConnection implements Testlet {
file.list();
th.fail("Exception expected");
} catch (IOException e) {
th.check(e.getMessage(), "Connection is open on a file: file:////provaDir/prova");
th.check(e.getMessage(), "Connection is open on a file: file:///Private/provaDir/prova");
}
OutputStream out = file.openOutputStream();
@ -377,7 +378,7 @@ public class TestFileConnection implements Testlet {
file = (FileConnection)Connector.open(dirPath + "provaDir/prova%2B");
th.check(file.getName(), "prova+");
th.check(file.getURL(), "file:////provaDir/prova%2B");
th.check(file.getURL(), "file:///Private/provaDir/prova%2B");
file.create();
file.close();
file = (FileConnection)Connector.open(dirPath + "provaDir/prova+");
@ -495,7 +496,7 @@ public class TestFileConnection implements Testlet {
file = (FileConnection)Connector.open(dirPath + "prov>");
th.fail("Exception expected");
} catch (IllegalArgumentException e) {
th.check(e.getMessage(), "Invalid file name in FileConnection Url: ///prov>");
th.check(e.getMessage(), "Invalid file name in FileConnection Url: ///Private/prov>");
}
// Check that the fileconn.dir.photos property value is longer than 8 characters.

Просмотреть файл

@ -0,0 +1,26 @@
package com.ibm.tck.client;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
/**
* ClientConnection must be implemented and included in any test suite
* suites. Implementations of this interface must be able to open the
* <code>url</code> passed and send the entire byte array <code>data</code>
* via the POST method to the url. The server will be able to handle chunked
* and non-chunked data.
*/
public interface ClientConnection {
/**
* This method is used to post data to the server via a URL.
* The protocol MUST be via HTTP 1.1 using the POST method.
*
* @param url The full URL for providing the test results
* @param data A byte array containing data.
*/
public abstract void postData(String url, byte[] data);
}

Просмотреть файл

@ -0,0 +1,80 @@
package com.ibm.tck.client;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
/**
* MIDP includes http so just use that as a transport layer.
*/
public class MIDPClientConnection implements ClientConnection {
/**
* @see com.ibm.tck.client.ClientConnection#postData(String, byte[])
*/
public void postData(String url, byte[] data) {
HttpConnection connection=null;
try {
connection = (HttpConnection) Connector.open(url);
connection.setRequestMethod("POST");
} catch (IOException e) {
System.out.print("Exception opening connection ");
System.out.println(e);
return;
} catch (SecurityException e) {
System.out.print("SecurityException opening connection ");
System.out.println(e);
}
OutputStream out=null;
try {
out = connection.openOutputStream();
out.write(data);
} catch (IOException e) {
System.out.print("Exception in opening and writing data ");
System.out.println(e);
try {
connection.close();
} catch (IOException innerEx) {}
}
InputStream in = null;
try {
in = connection.openInputStream();
} catch (Exception e1) {
}
if(in != null) {
byte buf[] = new byte[256];
try {
in.read(buf);
} catch (Exception e1) {
e1.printStackTrace();
}
try {
in.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
try {
out.close();
} catch (Exception e1) {
e1.printStackTrace();
}
try {
connection.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}

Просмотреть файл

@ -0,0 +1,43 @@
package com.ibm.tck.client;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/**
* MIDlet class that executes tests. Invokes a TestRunner with the MIDlet
* as a parameter. After the tests are executed, notifyDestroyed() is called.
*/
public class TCKMidlet extends MIDlet {
/**
* Performs two functions.
* <pre>
* new TestRunner(this);
* notifyDestroyed();
* </pre>
* @see MIDlet#startApp().
*/
protected void startApp() throws MIDletStateChangeException {
new TestRunner(this);
notifyDestroyed();
}
/**
* @see MIDlet#pauseApp()
*/
protected void pauseApp() {
}
/**
* @see MIDlet#destroyApp(boolean)
*/
protected void destroyApp(boolean flag) throws MIDletStateChangeException {
}
}

Просмотреть файл

@ -0,0 +1,138 @@
package com.ibm.tck.client;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
import java.io.*;
import java.util.Hashtable;
import java.util.Vector;
/**
* TestCase is the root of functionality for a Unit test. A Unit test may
* in fact have several tests. There is a possibility of some/all of the tests
* being excluded therefore naming of the tests is important.
*/
public abstract class TestCase {
private TestRunner runner;
private String currentTestName;
private StringBuffer testLog;
private long startTime;
private final static String CRLF = "\r\n";
protected final void testRunner(TestRunner runner) {
this.runner = runner;
}
/**
* The implementation of the runTests() method should invoke a
* series of tests. The tests should be executed like the following.
* <pre>
* <code>
* if (isTestValid("test0001"))
* test0001();
* if (isTestValid("test0002"))
* test0002();
* </code>
* </pre>
* Each test then makes use of ONE (1) assertTrue(String, boolean) and
* the reports are sent back to the server using DataOutputStreams:
* <pre>
* <code>
* String -> com.company.subpackage.test.TestClass#test0001
* boolean -> pass or fail
* String -> testDescription
* String -> testLog
* long -> elapsedTime
* </code>
* </pre>
*
* TestCase can make use of log(String) which appends to the testLog.
*
* TestCase can make use of interactiveMessage(String) which will force the TCK Harness
* to display a message to the user. When the user presses 'Continue' this method will
* return in the testcase and you can proceed with the test.
*
* TestCase can make use of options() to find out what options the TCK Harness is running with.
*/
public abstract void runTests();
/**
* Determines whether or not a specific test has been excluded or not. The
* TestCase class will take care of fully qualifying the name so you need
* only pass the test name.
*
* @param testName the name of the test to check validity for
* @return a boolean indicating whether or not this test is valid
*/
public final boolean isTestValid(String testName) {
StringBuffer fullName = new StringBuffer();
fullName.append(this.getClass().getName());
fullName.append("#");
fullName.append(testName);
currentTestName = fullName.toString();
testLog = new StringBuffer();
boolean result = !runner.isExcluded(currentTestName) &&
runner.isFiltered(currentTestName);
startTime = System.currentTimeMillis();
return result;
}
/**
* Add a message to the log during 1 test run. A CR/LF combination is added
* after each logMessage. The log is reset after each <code>isTestValid()</code>
* call.
*
* @param logMessage A String of information to show during the test run
*/
public final void log(String logMessage) {
if (logMessage==null) return;
testLog.append(logMessage);
testLog.append(CRLF);
}
/**
* Assertion point for deciding whether a test passes or fails. The description
* should match the XML entry for the test. The full test name, results, description
* and log are sent to the server. Care should be taken to call this method once
* per test otherwise the server may get out of sync.
*
* @param description A string describing the test. Should be the same as the description in the XML file.
* @param mustBeTrue A boolean stating whether the test passed (<code>true</code>) or failed (<code>false</code>).
*/
public final void assertTrue(String description, boolean mustBeTrue) {
long elapsedTime = System.currentTimeMillis() - startTime;
runner.postResults(currentTestName, mustBeTrue, description, testLog.toString(), elapsedTime);
}
/**
* Request for the TCK Server to display an interactive message to the user. Upon returning from
* this call the testcase can continue.
*
* @param description A String to display interactively to the user operating the TCK Harness.
*/
public final void interactiveMessage(String message) {
runner.postMessage(currentTestName, message);
}
/**
* Answer a Hashtable of options that were set at the time this testcase was generated.
*
* @return a Hashtable of options, possibly empty but never <code>null</code>.
*/
public final Hashtable getOptions() {
return runner.getOptions();
}
/**
* Answer an Object that is the MIDlet running the testcase. If the <code>TestCase</code> makes any modification
* to the MIDlet they should be undone before the <code>TestCase</code> finishes.
*
* @return an Object (or null) representing the MIDlet the TestCase is running in.
*/
public final Object getMidlet() {
return runner.getMidlet();
}
}

Просмотреть файл

@ -0,0 +1,325 @@
package com.ibm.tck.client;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
import java.io.*;
import java.util.*;
/**
* The main entry point for all tests.
* TestRunner has the following sequence.<br>
* <UL>
* <LI>invoked with main(), if the first arg is -noserver, simply run tests and write to stdout (useful for debugging)</LI>
* <LI>load 'testres' resource file (In DataOutputStream format)</LI>
* <LI>load client communication class name</LI>
* <LI>load test server URL for results</LI>
* <LI>load test server URL for interactive tests</LI>
* <LI>load number of tests</LI>
* <LI>load each test name and store</LI>
* <LI>load number of excludes</LI>
* <LI>load each exclude test name and store</LI>
* <LI>load all options set for this test run</LI>
* <LI>close resource file</LI>
* <LI>for each test name
* <UL>
* <LI>lookup class and instantiate</LI>
* <LI>call runTests()</LI>
* <LI>runTests() runs each test in a test checking first to see if it excluded</LI>
* <LI>results are sent back to the server (if not -noserver)</LI>
* </UL>
* <LI>done</LI>
* </UL>
* One difference is that if the TestRunner is invoked by the TCKMidlet, an object
* representing the MIDlet is set in the runner. Any <code>TestCase</code> can
* cast the result of <code>getMidlet()</code> to a MIDlet if they know they
* are running on MIDP.
*
*/
public final class TestRunner {
private Object midlet;
private String serverURL;
private String interactiveURL;
private String clientClass;
private Vector excludes;
private Hashtable options = new Hashtable();
private Vector testClasses;
private Vector filters;
static private boolean noserver = false;
private ByteArrayOutputStream testResults;
private ByteArrayOutputStream output;
private ClientConnection clientConnection;
private int _passed, _failed, _excluded;
/**
* main() should be invoded with no arguments. If -noserver is passed as the first argument, no attempt
* is made to send the results back to a server. This is useful for testing individual
* tests.
*
* @param args string array of args but only supported option is -noserver indicating whether or not to send results back to server.
*/
public static void main(String[] args) {
if (args.length > 0) {
if (args[0].toLowerCase().equals("-noserver"))
noserver = true;
else {
System.out.println("Only option is [-noserver]");
}
}
new TestRunner();
}
/**
* Constructor for TestRunner.
*/
public TestRunner() {
excludes = new Vector(1);
testClasses = new Vector(1);
filters = new Vector(1);
testResults = new ByteArrayOutputStream();
output = new ByteArrayOutputStream();
run();
}
/**
* Constructor for TestRunner.
*
* @param midlet An object representing the MIDlet the TestRunner is running on.
*/
public TestRunner(Object midlet) {
excludes = new Vector(1);
testClasses = new Vector(1);
filters = new Vector(1);
testResults = new ByteArrayOutputStream();
output = new ByteArrayOutputStream();
this.midlet = midlet;
run();
}
/**
* Answer a boolean if testName, comprised of a full class name and test description,
* is excluded.
*
* @param testName the fully qualified name
* @return a boolean indicating whether or not a testName is excluded
*/
public boolean isExcluded(String testName) {
boolean result = excludes.contains(testName);
if (result) _excluded++;
return result;
}
/**
* Answer a boolean if testName, comprised of a full class name and test description,
* is included based on current filter settings.
*
* @param testName the fully qualified name
* @return boolean indicating whether or not a testName is filtered
*/
public boolean isFiltered(String testName) {
if(filters.size() == 0)
return true;
for(int i = 0; i<filters.size(); i++) {
if(testName.indexOf((String)filters.elementAt(i)) != -1)
return true;
}
return false;
}
protected void postResults(String testName, boolean passed, String description, String testLog, long elapsedTime) {
System.out.print(testName);
if (passed)
_passed++;
else
_failed++;
System.out.print(passed ? " passed (" : " failed (");
System.out.print(description);
System.out.println(")");
if (testLog.length() > 0) {
System.out.print("TESTLOG: ");
System.out.println(testLog);
}
if (!noserver) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dataOutput = new DataOutputStream(baos);
dataOutput.writeUTF(testName);
dataOutput.writeBoolean(passed);
dataOutput.writeUTF(description);
dataOutput.writeUTF(testLog);
dataOutput.writeLong(elapsedTime);
dataOutput.close();
clientConnection.postData(serverURL, baos.toByteArray());
} catch (Exception e) {
System.out.println("Error in assertTrue()");
System.out.println("Exception " + e);
}
}
}
protected Hashtable getOptions() {
return options;
}
protected Object getMidlet() {
return midlet;
}
protected void postMessage(String testName, String description) {
System.out.print(testName);
System.out.println(" Interactive request:");
System.out.println(description);
if (noserver) {
System.out.println("Error, there is no server specified");
return;
} else {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dataOutput = new DataOutputStream(baos);
dataOutput.writeUTF(testName);
dataOutput.writeUTF(description);
dataOutput.close();
clientConnection.postData(interactiveURL, baos.toByteArray());
} catch (Exception e) {
System.out.println("Error in assertTrue()");
System.out.println("Exception " + e);
}
}
}
private void run() {
// if (!loadTestResources()) return;
loadHardcodedTestResources();
if (!noserver) {
try {
Class clazz = Class.forName(clientClass);
clientConnection = (ClientConnection) clazz.newInstance();
} catch (Throwable e) {
System.out.println("Connection class " + clientClass + " cannot be instantiated");
return;
}
}
Enumeration e = testClasses.elements();
while (e.hasMoreElements()) {
String className = (String) e.nextElement();
Class testClass=null;
try {
testClass = Class.forName(className);
TestCase tests = (TestCase) testClass.newInstance();
tests.testRunner(this);
tests.runTests();
} catch (Exception testException) {
System.out.println("Exception running test " + className);
System.out.println(testException);
return;
}
}
StringBuffer results = new StringBuffer();
results.append(_passed + _failed + _excluded);
results.append(" tests, ");
results.append(_passed);
results.append(" passed, ");
results.append(_excluded);
results.append(" excluded, ");
results.append(_failed);
results.append(" failed\r\n");
if (_failed == 0)
results.append("All Tests Passed");
else
results.append("There were test failures");
System.out.println(results);
}
private boolean loadTestResources() {
InputStream res = this.getClass().getResourceAsStream("/testres");
if (res == null) {
System.out.println("Could not find TestRunner resource file, exiting...");
return false;
}
// Any exceptions result in test failure
try {
DataInputStream dis = new DataInputStream(res);
// Get the Client Class to use as a connection
clientClass = dis.readUTF();
// Get the server URL to write results to
serverURL = dis.readUTF();
// Get the server URL for interactive tests
interactiveURL = dis.readUTF();
// Get the number of tests classes
int testClassCount = dis.readInt();
// Load all the testClass names
while (testClassCount-- > 0) {
testClasses.addElement(dis.readUTF());
}
int excludeCount = dis.readInt();
// Load all the testClass names
while (excludeCount-- > 0) {
excludes.addElement(dis.readUTF());
}
// Load the number of options
int optionCount = dis.readInt();
while (optionCount-- > 0) {
String key = dis.readUTF();
String value = dis.readUTF();
options.put(key, value);
}
//Load the test filters
int filterCount = dis.readInt();
while(filterCount-- > 0) {
filters.addElement(dis.readUTF());
}
res.close();
} catch (IOException e) {
System.out.println("Resource file contains errors, exiting...");
return false;
}
return true;
}
private void loadHardcodedTestResources() {
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.ConnectionClosedException.Init");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.AvailableSize");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.CanRead");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.CanWrite");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.Create");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.Delete");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.DirectorySize");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.Exists");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.FileSize");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.GetName");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.GetPath");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.GetURL");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.IsDirectory");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.IsHidden");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.LastModified");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.List");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.Mkdir");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.Open");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.OpenDataInputStream");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.OpenDataOutputStream");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.OpenInputStream");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.OpenOutputStream");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.OpenOutputStream_Long");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.PackageDiscovery");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.Rename");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.SetFileConnection");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.SetHidden");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.SetReadable");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.SetWritable");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.TotalSize");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.Truncate");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileConnection.UsedSize");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileSystemListener.RootChanged");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileSystemRegistry.AddFileSystemListener");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileSystemRegistry.ListRoots");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.FileSystemRegistry.RemoveFileSystemListener");
testClasses.addElement("com.ibm.tck.javax.microedition.io.file.IllegalModeException.Init");
options.put("FilesystemTestPath", "//tcktestdir/");
}
}

Просмотреть файл

@ -0,0 +1,28 @@
package com.ibm.tck.javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.ConnectionClosedException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class Init extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
}
/**
* Tests that a message that is set can be retrieved
*/
public void test0001() {
ConnectionClosedException e = new ConnectionClosedException("foo");
assertTrueWithLog("Tests that a message that is set can be retrieved", "foo".equals(e.getMessage()));
}
}

Просмотреть файл

@ -0,0 +1,257 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class AvailableSize extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
}
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
long availableSize = conn.availableSize();
addOperationDesc("first availableSize() call returned " + availableSize);
int incrementSize = 4096;
byte buf[] = new byte[incrementSize];
os = conn.openOutputStream();
for (int i=0; i<4; i++) {
addOperationDesc("writing " + incrementSize + " bytes to disk");
os.write(buf);
}
os.close();
os = null;
long availableSize2 = conn.availableSize();
addOperationDesc("second availableSize() call returned " + availableSize2 + " (should be less than first call)");
passed = availableSize2<availableSize;
} finally {
if (os != null) os.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests availableSize()", passed);
}
/**
* Tests availableSize() on two different connections on the same root volume
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test2", Connector.READ_WRITE);
long availableSize1 = conn1.availableSize();
addOperationDesc("first availableSize() call returned " + availableSize1);
long availableSize2 = conn2.availableSize();
addOperationDesc("second availableSize() call returned " + availableSize2 + " (should be identical to previous result");
passed = availableSize1==availableSize2;
} finally {
if (conn1 != null) {
conn1.close();
}
if (conn2 != null) {
conn2.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests availableSize() on two different connections on the same root volume", passed);
}
/**
* ConnectionClosedException thrown if invoked on a closed connection
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
conn.close();
try {
conn.availableSize();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if invoked on a closed connection", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0004() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
conn.availableSize();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests availableSize() in Connector.READ mode
*/
public void test0005() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
long availableSize = conn.availableSize();
addOperationDesc("availableSize() call returned " + availableSize);
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests availableSize() in Connector.READ mode", passed);
}
/**
* Tests availableSize() on a non-existent file system
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
long availableSize = conn.availableSize();
addOperationDesc("availableSize() call returned " + availableSize);
passed = availableSize==-1;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests availableSize() on a non-existent file system", passed);
}
/**
* Tests availableSize() on a non-existent host
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
try {
long availableSize = conn.availableSize();
addOperationDesc("availableSize() call returned " + availableSize);
passed = availableSize == -1;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests availableSize() on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,477 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class CanRead extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
if (isTestValid("test0012")) test0012();
if (isTestValid("test0013")) test0013();
if (isTestValid("test0014")) test0014();
if (isTestValid("test0015")) test0015();
}
/**
* Tests canRead() on a readable file
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Setting file as readable");
conn.setReadable(true);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
passed = canRead==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canRead() on a readable file", passed);
}
/**
* Tests canRead() on a non-readable file
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Setting file as non-readable");
conn.setReadable(false);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
passed = canRead==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canRead() on a non-readable file", passed);
}
/**
* Tests canRead() on a readable directory
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Setting directory as readable");
conn.setReadable(true);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
passed = canRead==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canRead() on a readable directory", passed);
}
/**
* Tests canRead() on a non-readable directory
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Setting directory as non-readable");
conn.setReadable(false);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
passed = canRead==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canRead() on a on-readable directory", passed);
}
/**
* Tests canRead() on a file (readable attribute is NOT supported by filesystem)
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Setting file as non-readable");
conn.setReadable(false);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
passed = canRead==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canRead() on a file (readable attribute is NOT supported by filesystem)", passed);
}
/**
* Tests canRead() on a directory (readable attribute is NOT supported by filesystem)
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Setting directory as non-readable");
conn.setReadable(false);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
passed = canRead==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canRead() on a directory (readable attribute is NOT supported by filesystem)", passed);
}
/**
* canRead() throws ConnectionClosedException if connection is closed
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Closing connection");
conn.close();
try {
addOperationDesc("Attempting to call canRead() on a closed connection");
boolean canRead = conn.canRead();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("canRead() throws ConnectionClosedException if connection is closed", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0008() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
conn.canRead();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests canRead() in Connector.READ mode
*/
public void test0009() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
boolean canRead = conn.canRead();
addOperationDesc("canRead() call returned " + canRead);
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canRead() in Connector.READ mode", passed);
}
/**
* Tests canRead() on a non-existent file
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
passed = canRead==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("canRead() returns false for a non-existent file", passed);
}
/**
* Tests canRead() on a non-existent file (readable attribute is NOT supported by filesystem)
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
passed = canRead==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("canRead() returns false for a non-existent file (readable attribute is NOT supported by filesystem)", passed);
}
/**
* Tests canRead() on a non-existent directory
*/
public void test0012() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
passed = canRead==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("canRead() returns false for a non-existent directory", passed);
}
/**
* Tests canRead() on a non-existent directory (readable attribute is NOT supported by filesystem)
*/
public void test0013() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
passed = canRead==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("canRead() returns false for a non-existent directory (readable attribute is NOT supported by filesystem)", passed);
}
/**
* Tests canRead() on a non-existent file system
*/
public void test0014() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
boolean canRead = conn.canRead();
addOperationDesc("canRead() call returned " + canRead);
passed = canRead==false;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canRead() on a non-existent file system", passed);
}
/**
* Tests canRead() on a non-existent host
*/
public void test0015() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
boolean canRead = conn.canRead();
addOperationDesc("canRead() call returned " + canRead);
passed = canRead==false;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canRead() on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,476 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class CanWrite extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
if (isTestValid("test0012")) test0012();
if (isTestValid("test0013")) test0013();
if (isTestValid("test0014")) test0014();
if (isTestValid("test0015")) test0015();
}
/**
* Tests canWrite() on a writable file
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Setting file as writable");
conn.setWritable(true);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
passed = canWrite==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canWrite() on a writable file", passed);
}
/**
* Tests canWrite() on a non-writable file
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Setting file as non-writable");
conn.setWritable(false);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
passed = canWrite==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canWrite() on a non-writable file", passed);
}
/**
* Tests canWrite() on a writable directory
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Setting directory as writable");
conn.setWritable(true);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
passed = canWrite==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canWrite() on a writable directory", passed);
}
/**
* Tests canWrite() on a non-writable directory
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Setting directory as non-writable");
conn.setWritable(false);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
passed = canWrite==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canWrite() on a on-writable directory", passed);
}
/**
* Tests canWrite() on a file (writable attribute is NOT supported by filesystem)
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Setting file as non-writable");
conn.setWritable(false);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
passed = canWrite==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canWrite() on a file (writable attribute is NOT supported by filesystem)", passed);
}
/**
* Tests canWrite() on a directory (writable attribute is NOT supported by filesystem)
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Setting directory as non-writable");
conn.setWritable(false);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
passed = canWrite==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canWrite() on a directory (writable attribute is NOT supported by filesystem)", passed);
}
/**
* canWrite() throws ConnectionClosedException if connection is closed
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Closing connection");
conn.close();
try {
addOperationDesc("Attempting to call canWrite() on a closed connection");
boolean canWrite = conn.canWrite();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("canWrite() throws ConnectionClosedException if connection is closed", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0008() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
conn.canWrite();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests canWrite() in Connector.READ mode
*/
public void test0009() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() call returned " + canWrite);
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canWrite() in Connector.READ mode", passed);
}
/**
* Tests canWrite() on a non-existent file
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
passed = canWrite==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("canWrite() returns false for a non-existent file", passed);
}
/**
* Tests canWrite() on a non-existent file (writable attribute is NOT supported by filesystem)
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
passed = canWrite==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("canWrite() returns false for a non-existent file (writable attribute is NOT supported by filesystem)", passed);
}
/**
* Tests canWrite() on a non-existent directory
*/
public void test0012() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
passed = canWrite==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("canWrite() returns false for a non-existent directory", passed);
}
/**
* Tests canWrite() on a non-existent directory (writable attribute is NOT supported by filesystem)
*/
public void test0013() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
passed = canWrite==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("canWrite() returns false for a non-existent directory (writable attribute is NOT supported by filesystem)", passed);
}
/**
* Tests canWrite() on a non-existent file system
*/
public void test0014() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() call returned " + canWrite);
passed = canWrite==false;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canWrite() on a non-existent file system", passed);
}
/**
* Tests canWrite() on a non-existent host
*/
public void test0015() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() call returned " + canWrite);
passed = canWrite==false;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests canWrite() on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,293 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class Create extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
}
/**
* create() creates a new file
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
addOperationDesc("Creating file");
conn.create();
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("create() creates a new file", passed);
}
/**
* IOException thrown if target is a directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
addOperationDesc("Attempting to create directory");
try {
conn.create();
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if target is a directory", passed);
}
/**
* IOException thrown if target is an existing file
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Attempting to create file again");
try {
conn.create();
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if target is an existing file", passed);
}
/**
* ConnectionClosedException thrown if connection is closed
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
conn.close();
try {
addOperationDesc("Attempting to call create() on closed connection");
conn.create();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if invoked on a closed connection", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.READ mode
*/
public void test0005() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
try {
conn.create();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests create() in Connector.WRITE mode
*/
public void test0006() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = null;
FileConnection conn2 = null;
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn2);
addOperationDesc("Creating file");
conn.create();
boolean exists = conn2.exists();
addOperationDesc("exists() returned " + exists);
passed = exists==true;
} finally {
if (conn != null) conn.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests create() in Connector.WRITE mode", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.create();
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.create();
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,457 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class Delete extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
if (isTestValid("test0012")) test0012();
}
/**
* Tests delete() on a file
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Deleting file");
conn.delete();
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists == false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests delete() on a file", passed);
}
/**
* Tests delete() on a directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Deleting directory");
conn.delete();
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists ==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests delete() on a file", passed);
}
/**
* Tests delete() on a non-empty directory throws IOException
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/file", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn1.getURL());
ensureDirExists(conn1);
addOperationDesc("Creating file: " + conn2.getURL());
ensureFileExists(conn2);
try {
addOperationDesc("Attempting to delete a non-empty directory");
conn1.delete();
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
boolean exists = conn1.exists();
addOperationDesc("exists() returned " + exists);
passed = exists == true;
}
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown when trying to delete() on a non-empty directory.", passed);
}
/**
* Tests delete() on a non-existent file throws IOException
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
addOperationDesc("Attempting to delete the file again");
conn.delete();
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists == false;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown when trying to delete() a non-existent file", passed);
}
/**
* Tests delete() on a non-existent directory throws IOException
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
try {
addOperationDesc("Attempting to delete the directory again");
conn.delete();
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists == false;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown when trying to delete() a non-existent directory", passed);
}
/**
* Input stream is closed after delete()
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening input stream on file");
InputStream is = conn.openInputStream();
try {
addOperationDesc("Deleting file");
conn.delete();
try {
is.read();
addOperationDesc("No IOException thrown from InputStream.read()");
passed = false;
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown from InputStream.read()");
}
} finally {
is.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Input stream is closed after delete()", passed);
}
/**
* Output stream is closed after delete()
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening output stream on file");
OutputStream os = conn.openOutputStream();
try {
addOperationDesc("Deleting file");
conn.delete();
try {
os.write(0);
addOperationDesc("No IOException thrown from OutputStream.write()");
passed = false;
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown from OutputStream.write()");
}
} finally {
os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Output stream is closed after delete()", passed);
}
/**
* ConnectionClosedException thrown if connection is closed
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Closing connection");
conn.close();
try {
addOperationDesc("Attempting to call delete() on closed connection");
conn.delete();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if invoked on a closed connection", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.READ mode
*/
public void test0009() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
try {
conn.delete();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests delete() in Connector.WRITE mode
*/
public void test0010() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = null;
FileConnection conn2 = null;
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn2);
addOperationDesc("Deleting file");
conn.delete();
boolean exists = conn2.exists();
addOperationDesc("exists() returned " + exists);
passed = exists==false;
} finally {
if (conn != null) conn.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests delete() in Connector.WRITE mode", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.delete();
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0012() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.delete();
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,427 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class DirectorySize extends TestCaseWithLog {
protected FileConnection testFile2;
protected FileConnection testFile3;
protected FileConnection testSubSubDir;
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
}
/**
* Tests directorySize() on empty directory
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
long directorySize = conn.directorySize(true);
addOperationDesc("directorySize(true) returned " + directorySize);
passed = directorySize==0;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests directorySize() on empty directory", passed);
}
/**
* Tests directorySize() on directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
FileConnection conn3 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/file1", Connector.READ_WRITE);
conn3 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/file2", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn1.getURL());
ensureDirExists(conn1);
addOperationDesc("Creating file with a size of 64 bytes: " + conn2.getURL());
ensureFileExists(conn2);
ensureFileSize(conn2, 64);
addOperationDesc("Creating file with a size of 32 bytes: " + conn3.getURL());
ensureFileExists(conn3);
ensureFileSize(conn3, 32);
long directorySize = conn1.directorySize(true);
addOperationDesc("directorySize(true) returned " + directorySize);
passed = directorySize==96;
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
if (conn3 != null) conn3.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog(" Tests directorySize() on directory", passed);
}
/**
* Tests directorySize() on directory with subdirectories (with includeSubDirs as false)
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
FileConnection conn3 = null;
FileConnection conn4 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/file1", Connector.READ_WRITE);
conn3 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/subdir/", Connector.READ_WRITE);
conn4 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/subdir/file2", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn1.getURL());
ensureDirExists(conn1);
addOperationDesc("Creating file with a size of 64 bytes: " + conn2.getURL());
ensureFileExists(conn2);
ensureFileSize(conn2, 64);
addOperationDesc("Creating directory: " + conn3.getURL());
ensureDirExists(conn3);
addOperationDesc("Creating file with a size of 32 bytes: " + conn4.getURL());
ensureFileExists(conn4);
ensureFileSize(conn4, 32);
long directorySize = conn1.directorySize(false);
addOperationDesc("directorySize(false) returned " + directorySize);
passed = directorySize==64;
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
if (conn3 != null) conn3.close();
if (conn4 != null) conn4.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests directorySize() on directory with subdirectories (with includeSubDirs as false)", passed);
}
/**
* Tests directorySize() on directory with subdirectories (with includeSubDirs as true)
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
FileConnection conn3 = null;
FileConnection conn4 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/file1", Connector.READ_WRITE);
conn3 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/subdir/", Connector.READ_WRITE);
conn4 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/subdir/file2", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn1.getURL());
ensureDirExists(conn1);
addOperationDesc("Creating file with a size of 64 bytes: " + conn2.getURL());
ensureFileExists(conn2);
ensureFileSize(conn2, 64);
addOperationDesc("Creating directory: " + conn3.getURL());
ensureDirExists(conn3);
addOperationDesc("Creating file with a size of 32 bytes: " + conn4.getURL());
ensureFileExists(conn4);
ensureFileSize(conn4, 32);
long directorySize = conn1.directorySize(true);
addOperationDesc("directorySize(true) returned " + directorySize);
passed = directorySize==96;
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
if (conn3 != null) conn3.close();
if (conn4 != null) conn4.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests directorySize() on directory with subdirectories (with includeSubDirs as true)", passed);
}
/**
* ConnectionClosedException thrown if invoked on a closed connection
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
conn.close();
try {
conn.directorySize(true);
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if invoked on a closed connection", passed);
}
/**
* IOException thrown if invoked on a file
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file" + conn.getURL());
ensureFileExists(conn);
try {
addOperationDesc("Attempting to call directorySize() on a file");
conn.directorySize(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a file", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0007() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.WRITE);
try {
try {
conn.directorySize(true);
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests directorySize() in Connector.READ mode
*/
public void test0008() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ);
try {
long directorySize = conn.directorySize(false);
addOperationDesc("directorySize() call returned " + directorySize);
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests directorySize() in Connector.READ mode", passed);
}
/**
* Tests directorySize() on a non-existent directory
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
long directorySize = conn.directorySize(true);
addOperationDesc("directorySize(true) returned " + directorySize);
passed = directorySize==-1;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests directorySize() on a non-existent directory", passed);
}
/**
* Tests directorySize() on a non-existent file system
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"testdir/", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
long directorySize = conn.directorySize(true);
addOperationDesc("directorySize() call returned " + directorySize);
passed = directorySize==-1;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests directorySize() on a non-existent file system", passed);
}
/**
* Tests directorySize() on a non-existent host
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"testdir/", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
try {
long directorySize = conn.directorySize(true);
addOperationDesc("directorySize() call returned " + directorySize);
passed = directorySize == -1;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests directorySize() on a non-existent host", passed);
}
protected void ensureFileSize(FileConnection conn, int fileSize) throws IOException {
OutputStream os = conn.openOutputStream();
try {
os.write(new byte[fileSize]);
os.flush();
} finally {
os.close();
}
}
}

Просмотреть файл

@ -0,0 +1,295 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class Exists extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
}
/**
* Tests exists() on a file
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests exists() on a file", passed);
}
/**
* Tests exists() on a directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests exists() on a directory", passed);
}
/**
* Tests exists() on a non-existent file
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests exists() on a non-existent file", passed);
}
/**
* Tests exists() on a non-existent directory
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests exists() on a non-existent directory", passed);
}
/**
* ConnectionClosedException thrown if invoked on a closed connection
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
conn.close();
try {
conn.exists();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if invoked on a closed connection", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0006() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
conn.exists();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests exists() in Connector.READ mode
*/
public void test0007() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
FileConnection conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
boolean exists = conn2.exists();
addOperationDesc("exists() returned " + exists);
passed = exists==true;
} finally {
conn1.close();
conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests exists() in Connector.READ mode", passed);
}
/**
* Tests exists() on a non-existent file system
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"testdir/", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
boolean exists = conn.exists();
addOperationDesc("exists() call returned " + exists);
passed = exists==false;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests exists() on a non-existent file system", passed);
}
/**
* Tests exists() on a non-existent host
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"testdir/", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
boolean exists = conn.exists();
addOperationDesc("exists() call returned " + exists);
passed = exists==false;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests exists() on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,327 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class FileSize extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
}
/**
* Tests fileSize() on a file
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file with a size of 64 bytes: " + conn.getURL());
ensureFileExists(conn);
ensureFileSize(conn, 64);
long fileSize = conn.fileSize();
addOperationDesc("fileSize() returned " + fileSize);
passed = fileSize==64;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests fileSize() on a file", passed);
}
/**
* Tests fileSize() on a file with an open OutputStream
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os =null;
try {
addOperationDesc("Creating file with a size of 0 bytes: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening output stream on file");
os = conn.openOutputStream();
addOperationDesc("Writing and flushing 64 bytes to file");
os.write(new byte[64]);
os.flush();
long fileSize = conn.fileSize();
addOperationDesc("fileSize() returned " + fileSize);
passed = fileSize==64;
} finally {
if (os!=null) os.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests fileSize() on a file with an open OutputStream", passed);
}
/**
* ConnectionClosedException thrown if invoked on a closed connection
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
conn.close();
try {
conn.fileSize();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if invoked on a closed connection", passed);
}
/**
* IOException thrown if invoked on a directory
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory" + conn.getURL());
ensureDirExists(conn);
try {
addOperationDesc("Attempting to call fileSize() on a directory");
conn.fileSize();
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a file", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0005() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
conn.fileSize();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests fileSize() in Connector.READ mode
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Opening connection in READ mode");
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
addOperationDesc("Creating file with a size of 64 bytes: " + conn1.getURL());
ensureFileExists(conn1);
ensureFileSize(conn1, 64);
long fileSize = conn2.fileSize();
addOperationDesc("fileSize() returned " + fileSize);
passed = fileSize==64;
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests fileSize() in Connector.READ mode", passed);
}
/**
* Tests fileSize() on a non-existent file
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
long fileSize = conn.fileSize();
addOperationDesc("fileSize() returned " + fileSize);
passed = fileSize==-1;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests fileSize() on a non-existent file", passed);
}
/**
* Tests fileSize() on a non-existent file system
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
long fileSize = conn.fileSize();
addOperationDesc("fileSize() call returned " + fileSize);
passed = fileSize==-1;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests fileSize() on a non-existent file system", passed);
}
/**
* Tests fileSize() on a non-existent host
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
try {
long fileSize = conn.fileSize();
addOperationDesc("fileSize() call returned " + fileSize);
passed = fileSize == -1;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests fileSize() on a non-existent host", passed);
}
protected void ensureFileSize(FileConnection conn, int fileSize) throws IOException {
OutputStream os = conn.openOutputStream();
try {
os.write(new byte[fileSize]);
os.flush();
} finally {
os.close();
}
}
}

Просмотреть файл

@ -0,0 +1,383 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.util.Enumeration;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.FileSystemRegistry;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
import com.ibm.tck.javax.microedition.io.file.support.URLSupport;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class GetName extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
}
/**
* Tests getName() on a non-existing file url
*/
public void test0001() {
boolean passed = false;
try {
String url="file://"+getTestPath()+"file";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
ensureNotExists(conn);
try {
addOperationDesc("Using file url: " + url);
String name = conn.getName();
addOperationDesc("getName() returned " + name);
passed = "file".equals(name);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getName() on a non-existing file url", passed);
}
/**
* Tests getName() on a non-existing directory url
*/
public void test0002() {
boolean passed = false;
try {
String url="file://"+getTestPath()+"dir/";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
ensureNotExists(conn);
try {
addOperationDesc("Using directory url: " + url);
String name = conn.getName();
addOperationDesc("getName() returned " + name);
passed = "dir/".equals(name);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getName() on a non-existing directory url", passed);
}
/**
* Tests getName() on an existing file url
*/
public void test0003() {
boolean passed = false;
try {
String url="file://"+getTestPath()+"file";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
ensureFileExists(conn);
try {
addOperationDesc("Using file url: " + url);
String name = conn.getName();
addOperationDesc("getName() returned " + name);
passed = "file".equals(name);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getName() on an existing file url", passed);
}
/**
* Tests getName() on an existing directory url
*/
public void test0004() {
boolean passed = false;
try {
String url="file://"+getTestPath()+"dir/";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
ensureDirExists(conn);
try {
addOperationDesc("Using directory url: " + url);
String name = conn.getName();
addOperationDesc("getName() returned " + name);
passed = "dir/".equals(name);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getName() on an existing directory url", passed);
}
/**
* Tests getName() on an existing file, and a connection url ending with '/'
*/
public void test0005() {
boolean passed = false;
try {
String url0="file://"+getTestPath()+"file";
FileConnection conn0 = (FileConnection)Connector.open(url0, Connector.READ_WRITE);
addOperationDesc("Creating file: " + url0);
ensureFileExists(conn0);
conn0.close();
String url="file://"+getTestPath()+"file/";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
try {
addOperationDesc("Using directory url: " + url);
String name = conn.getName();
addOperationDesc("getName() returned " + name);
passed = "file".equals(name);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getName() on an existing file, and a connection url ending with '/'", passed);
}
/**
* Tests getName() on an existing directory, and a connection url not ending with '/'
*/
public void test0006() {
boolean passed = false;
try {
String url0 = "file://" + getTestPath() + "dir/";
FileConnection conn0 = (FileConnection)Connector.open(url0, Connector.READ_WRITE);
addOperationDesc("Creating directory: " + url0);
ensureDirExists(conn0);
conn0.close();
String url = "file://" + getTestPath() + "dir";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
try {
addOperationDesc("Using file url: " + url);
String name = conn.getName();
addOperationDesc("getName() returned " + name);
passed = "dir/".equals(name);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getName() on an existing directory,and a connection url not ending with '/'", passed);
}
/**
* Tests getName() on an encoded file URL
*/
public void test0007() {
boolean passed = false;
try {
String url="file://"+getTestPath()+"foo%5e%25bar";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
try {
addOperationDesc("Using file url: " + url);
String name = conn.getName();
addOperationDesc("getName() returned " + name);
passed = "foo^%bar".equals(name);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getName() on an encoded file URL", passed);
}
/**
* Tests if getName() returns in unescaped URL format
*/
public void test0008() {
boolean passed = false;
try {
String unEscapedUrl ="file://"+getTestPath()+ "a file";
FileConnection conn = (FileConnection)Connector.open(unEscapedUrl, Connector.READ_WRITE);
try {
addOperationDesc("Using file url: " + unEscapedUrl);
String name = conn.getName();
addOperationDesc("getName() returned: " + name);
passed = name.equals("a file");
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests if getName() returns in unescaped URL format", passed);
}
/**
* Tests getName() on a file url with host
*/
public void test0009() {
boolean passed = false;
try {
String url = "file://" + URLSupport.getPathWithHost(getTestPath())+ "file";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
try {
addOperationDesc("Using file url with host: " + url);
String name = conn.getName();
addOperationDesc("getName() returned " + name);
passed = name.equals("file");
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getName() on a file url with host", passed);
}
/**
* Tests getName() on file system roots
*/
public void test0010() {
// name for roots must be ""
boolean passed = false;
try {
Enumeration enum = FileSystemRegistry.listRoots();
while (enum.hasMoreElements()) {
String root = (String) enum.nextElement();
String url = "file:///" + root;
FileConnection conn = null;
try {
conn = (FileConnection) Connector.open(url, Connector.READ_WRITE);
} catch (SecurityException se) {
// this is an unaccessible file system,
// continue with the next file system.
continue;
}
try {
addOperationDesc("Using root url: " + url);
String name = conn.getName();
addOperationDesc("getName() returned " + name);
passed = name.equals("");
if (!passed) break;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getName() on file system roots", passed);
}
/**
* Tests getName() on file system roots with 'localhost' in file url
*/
public void test0011() {
// name for roots must be ""
boolean passed = false;
try {
Enumeration enum = FileSystemRegistry.listRoots();
while (enum.hasMoreElements()) {
String root = (String) enum.nextElement();
String url = "file://localhost/" + root;
FileConnection conn = null;
try {
conn = (FileConnection) Connector.open(url, Connector.READ_WRITE);
} catch (SecurityException se) {
// this is an unaccessible file system,
// continue with the next file system.
continue;
}
try {
addOperationDesc("Using root url: " + url);
String name = conn.getName();
addOperationDesc("getName() returned " + name);
passed = name.equals("");
if (!passed) break;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getName() on file system roots with 'localhost' in file url", passed);
}
}

Просмотреть файл

@ -0,0 +1,263 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.util.Enumeration;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.FileSystemRegistry;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
import com.ibm.tck.javax.microedition.io.file.support.URLSupport;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class GetPath extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
}
/**
* Tests getPath() on a file
*/
public void test0001() {
boolean passed = false;
try {
String testpath= getTestPath();
String url="file://" + testpath + "file";
passed = testConnectionPath(testpath, url);
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getPath() on a file", passed);
}
/**
* Tests getPath() on a directory
*/
public void test0002() {
boolean passed = false;
try {
String testpath= getTestPath();
String url="file://" + testpath + "dir/";
passed = testConnectionPath(testpath, url);
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getPath() on a file", passed);
}
/**
* Tests getPath() on a file with an encoded URL
*/
public void test0003() {
boolean passed = false;
try {
String testpath = getTestPath() + "foo%5e%25bar/";
String url="file://" + testpath + "file";
passed = testConnectionPath(testpath, url);
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getPath() on a file with an encoded URL", passed);
}
/**
* Tests getPath() on a file with an encoded URL, alternative
*/
public void test0004() {
boolean passed = false;
try {
String testpath = getTestPath() + "foo%5E%25bar/";
String url="file://" + testpath + "file";
passed = testConnectionPath(testpath, url);
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getPath() on a file with an encoded URL, alternative", passed);
}
/**
* Tests if getPath() returns in unescaped URL format
*/
public void test0005() {
boolean passed = false;
try {
String testpath= getTestPath() + "a directory/";
String url="file://" + testpath + "a file";
passed = testConnectionPath(testpath, url);
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests if getPath() returns in unescaped URL format", passed);
}
private boolean testConnectionPath(String testpath, String url) throws IOException {
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
try {
addOperationDesc("Using file url: " + url);
String path = conn.getPath();
addOperationDesc("getPath() returned: " + path);
String correctPath = URLSupport.getPathWithoutHost(testpath);
return path.equals(URLSupport.getUnescapedForm(correctPath));
} finally {
conn.close();
}
}
/**
* Tests getPath() on a file url with host
*/
public void test0006() {
boolean passed = false;
try {
String url = "file://" + URLSupport.getPathWithHost(getTestPath()) + "file";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
try {
addOperationDesc("Using file url with host: " + url);
String path = conn.getPath();
addOperationDesc("getPath() returned: " + path);
String correctPath = URLSupport.getPathWithoutHost(getTestPath());
passed = path.equals(URLSupport.getUnescapedForm(correctPath));
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getPath() on a file url with host", passed);
}
/**
* Tests getPath() on file system roots
*/
public void test0007() {
// path for roots must be "/" + root
boolean passed = false;
try {
Enumeration enum = FileSystemRegistry.listRoots();
while (enum.hasMoreElements()) {
String root = (String) enum.nextElement();
String url = "file:///" + root;
FileConnection conn = null;
try {
conn = (FileConnection) Connector.open(url, Connector.READ_WRITE);
} catch (SecurityException se) {
// this is an unaccessible file system,
// continue with the next file system.
continue;
}
try {
addOperationDesc("Using root url: " + url);
String path = conn.getPath();
addOperationDesc("getPath() returned: " + path);
passed = path.equals('/' + root);
if (!passed) break;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getPath() on file system roots", passed);
}
/**
* Tests getPath() on roots with 'localhost' in file url
*/
public void test0008() {
// path for roots must be "/" + root
boolean passed = false;
try {
Enumeration enum = FileSystemRegistry.listRoots();
while (enum.hasMoreElements()) {
String root = (String) enum.nextElement();
String url = "file://localhost/" + root;
FileConnection conn = null;
try {
conn = (FileConnection) Connector.open(url, Connector.READ_WRITE);
} catch (SecurityException se) {
// this is an unaccessible file system,
// continue with the next file system.
continue;
}
try {
addOperationDesc("Using root url: " + url);
String path = conn.getPath();
addOperationDesc("getPath() returned: " + path);
passed = path.equals('/' + root);
if (!passed) break;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getPath() on file system roots with 'localhost' in file url", passed);
}
}

Просмотреть файл

@ -0,0 +1,417 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.util.Enumeration;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.FileSystemRegistry;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
import com.ibm.tck.javax.microedition.io.file.support.URLSupport;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class GetURL extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
}
/**
* Tests getURL() on a non-existing file url
*/
public void test0001() {
boolean passed = false;
try {
String url = "file://" + getTestPath() + "file";
String escapedUrl = URLSupport.getEscapedForm(url);
String alternativeUrl = URLSupport.getAlternativeEscapedForm(url);
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
ensureNotExists(conn);
try {
addOperationDesc("Using file url: " + url);
String connUrl = conn.getURL();
addOperationDesc("getURL() returned: " + connUrl);
passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getURL() on a non-existing file url", passed);
}
/**
* Tests getURL() on a non-existing directory url
*/
public void test0002() {
boolean passed = false;
try {
String url = "file://" + getTestPath() + "dir/";
String escapedUrl = URLSupport.getEscapedForm(url);
String alternativeUrl = URLSupport.getAlternativeEscapedForm(url);
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
ensureNotExists(conn);
try {
addOperationDesc("Using directory url: " + url);
String connUrl = conn.getURL();
addOperationDesc("getURL() returned: " + connUrl);
passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getURL() on a non-existing directory url", passed);
}
/**
* Tests getURL() on an existing file url
*/
public void test0003() {
boolean passed = false;
try {
String url = "file://" + getTestPath() + "file";
String escapedUrl = URLSupport.getEscapedForm(url);
String alternativeUrl = URLSupport.getAlternativeEscapedForm(url);
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
ensureFileExists(conn);
try {
addOperationDesc("Using file url: " + url);
String connUrl = conn.getURL();
addOperationDesc("getURL() returned: " + connUrl);
passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getURL() on an existing file url", passed);
}
/**
* Tests getURL() on an existing directory url
*/
public void test0004() {
boolean passed = false;
try {
String url = "file://" + getTestPath() + "dir/";
String escapedUrl = URLSupport.getEscapedForm(url);
String alternativeUrl = URLSupport.getAlternativeEscapedForm(url);
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
ensureDirExists(conn);
try {
addOperationDesc("Using directory url: " + url);
String connUrl = conn.getURL();
addOperationDesc("getURL() returned: " + connUrl);
passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getURL() on an existing directory url", passed);
}
/**
* Tests getURL() on an existing file, and a connection url ending with '/'
*/
public void test0005() {
boolean passed = false;
try {
String url0="file://"+getTestPath()+"file";
FileConnection conn0 = (FileConnection)Connector.open(url0, Connector.READ_WRITE);
addOperationDesc("Creating file: " + url0);
ensureFileExists(conn0);
conn0.close();
String escapedUrl = URLSupport.getEscapedForm(url0);
String alternativeUrl = URLSupport.getAlternativeEscapedForm(url0);
String url = "file://" + getTestPath() + "file/";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
try {
addOperationDesc("Using directory url: " + url);
String connUrl = conn.getURL();
addOperationDesc("getURL() returned: " + connUrl);
passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getURL() on an existing file, and a connection url ending with '/'", passed);
}
/**
* Tests getURL() on an existing directory, and a connection url not ending with '/'
*/
public void test0006() {
boolean passed = false;
try {
String url0 = "file://" + getTestPath() + "dir/";
FileConnection conn0 = (FileConnection)Connector.open(url0, Connector.READ_WRITE);
addOperationDesc("Creating directory: " + url0);
ensureDirExists(conn0);
conn0.close();
String escapedUrl = URLSupport.getEscapedForm(url0);
String alternativeUrl = URLSupport.getAlternativeEscapedForm(url0);
String url = "file://" + getTestPath() + "dir";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
try {
addOperationDesc("Using file url: " + url);
String connUrl = conn.getURL();
addOperationDesc("getURL() returned: " + connUrl);
passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getURL() on an existing directory, and a connection url not ending with '/'", passed);
}
/**
* Tests getURL() on an encoded file URL
*/
public void test0007() {
boolean passed = false;
try {
String url="file://"+ getTestPath() +"foo%5e%25bar/file";
String escapedUrl = URLSupport.getEscapedForm(url);
String alternativeUrl = URLSupport.getAlternativeEscapedForm(url);
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
try {
addOperationDesc("Using file: " + url);
String connUrl = conn.getURL();
addOperationDesc("getURL() returned: " + connUrl);
passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getURL() on an encoded file URL", passed);
}
/**
* Tests if getURL() returns in escaped URL format
*/
public void test0008() {
boolean passed = false;
try {
String unEscapedUrl = "file://"+ getTestPath() +"a directory/a file";
String escapedUrl = URLSupport.getEscapedForm(unEscapedUrl);
String alternativeUrl = URLSupport.getAlternativeEscapedForm(unEscapedUrl);
FileConnection conn = (FileConnection)Connector.open(unEscapedUrl, Connector.READ_WRITE);
try {
addOperationDesc("Using file: " + unEscapedUrl);
String connUrl = conn.getURL();
addOperationDesc("getURL() returned: " + connUrl);
passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests if getURL() returns in escaped URL format", passed);
}
/**
* Tests getURL() on a file url with host
*/
public void test0009() {
boolean passed = false;
try {
String url = "file://" + URLSupport.getPathWithHost(getTestPath())+ "file";
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
try {
String escapedUrl = URLSupport.getEscapedForm(url);
String alternativeUrl = URLSupport.getAlternativeEscapedForm(url);
addOperationDesc("Using file url with host: " + url);
String connUrl= conn.getURL();
addOperationDesc("getURL() returned: " + connUrl);
passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getURL() on a file url with host", passed);
}
/**
* Tests getURL() on file system roots
*/
public void test0010() {
// url for roots must be something like "file:///root/" in the escaped form
boolean passed = false;
try {
Enumeration enum = FileSystemRegistry.listRoots();
while (enum.hasMoreElements()) {
String root = (String) enum.nextElement();
String url = "file:///" + root;
FileConnection conn = null;
try {
conn = (FileConnection) Connector.open(url, Connector.READ_WRITE);
} catch (SecurityException se) {
// this is an unaccessible file system,
// continue with the next file system.
continue;
}
try {
String escapedUrl = URLSupport.getEscapedForm(url);
String alternativeUrl = URLSupport.getAlternativeEscapedForm(url);
addOperationDesc("Using root url: " + url);
String connUrl = conn.getURL();
addOperationDesc("getUrl() returned: " + connUrl);
passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
if (!passed) break;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getURL() on file system roots", passed);
}
/**
* Tests getURL() on file system roots with 'localhost' in file url
*/
public void test0011() {
// url for roots must be something like "file:///root/" in the escaped form
boolean passed = false;
try {
Enumeration enum = FileSystemRegistry.listRoots();
while (enum.hasMoreElements()) {
String root = (String) enum.nextElement();
String url = "file://localhost/" + root;
FileConnection conn = null;
try {
conn = (FileConnection) Connector.open(url, Connector.READ_WRITE);
} catch (SecurityException se) {
// this is an unaccessible file system,
// continue with the next file system.
continue;
}
try {
String escapedUrl = URLSupport.getEscapedForm(url);
String alternativeUrl = URLSupport.getAlternativeEscapedForm(url);
addOperationDesc("Using root url: " + url);
String connUrl = conn.getURL();
addOperationDesc("getURL() returned: " + connUrl);
passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
if (!passed) break;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests getURL() on file system roots with 'localhost' in file url", passed);
}
}

Просмотреть файл

@ -0,0 +1,302 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class IsDirectory extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
}
/**
* Tests isDirectory() on a file
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
boolean isDirectory = conn.isDirectory();
addOperationDesc("isDirectory() returned " + isDirectory);
passed = isDirectory==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isDirectory() on a file", passed);
}
/**
* Tests isDirectory() on a directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
boolean isDirectory = conn.isDirectory();
addOperationDesc("isDirectory() returned " + isDirectory);
passed = isDirectory==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isDirectory() on a file", passed);
}
/**
* Tests isDirectory() on a non-existent file URL
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
boolean isDirectory = conn.isDirectory();
addOperationDesc("isDirectory() returned " + isDirectory);
passed = isDirectory==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isDirectory() on a non-existent file URL returns false", passed);
}
/**
* Tests isDirectory() on a non-existent directory URL
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
boolean isDirectory = conn.isDirectory();
addOperationDesc("isDirectory() returned " + isDirectory);
passed = isDirectory==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isDirectory() on a non-existent directory URL returns false", passed);
}
/**
* ConnectionClosedException thrown if invoked on a closed connection
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
conn.close();
try {
conn.isDirectory();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if invoked on a closed connection", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0006() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
conn.isDirectory();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests isDirectory() in Connector.READ mode
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Opening connection in READ mode");
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ);
addOperationDesc("Creating directory: " + conn1.getURL());
ensureDirExists(conn1);
boolean isDirectory = conn2.isDirectory();
addOperationDesc("isDirectory() returned " + isDirectory);
passed = isDirectory==true;
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isDirectory() in Connector.READ mode", passed);
}
/**
* Tests isDirectory() on a non-existent file system
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"testdir/", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
boolean isDirectory = conn.isDirectory();
addOperationDesc("isDirectory() call returned " + isDirectory);
passed = isDirectory==false;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isDirectory() on a non-existent file system", passed);
}
/**
* Tests isDirectory() on a non-existent host
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"testdir/", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
boolean isDirectory = conn.isDirectory();
addOperationDesc("isDirectory() call returned " + isDirectory);
passed = isDirectory==false;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isDirectory() on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,476 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class IsHidden extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
if (isTestValid("test0012")) test0012();
if (isTestValid("test0013")) test0013();
if (isTestValid("test0014")) test0014();
if (isTestValid("test0015")) test0015();
}
/**
* Tests isHidden() on a hidden file
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Setting file as hidden");
conn.setHidden(true);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
passed = isHidden==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isHidden() on a hidden file", passed);
}
/**
* Tests isHidden() on a non-hidden file
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Setting file as non-hidden");
conn.setHidden(false);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
passed = isHidden==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isHidden() on a non-hidden file", passed);
}
/**
* Tests isHidden() on a hidden directory
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Setting directory as hidden");
conn.setHidden(true);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
passed = isHidden==true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isHidden() on a hidden directory", passed);
}
/**
* Tests isHidden() on a non-hidden directory
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Setting directory as non-hidden");
conn.setHidden(false);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
passed = isHidden==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isHidden() on a non-hidden directory", passed);
}
/**
* Tests isHidden() on a file (hidden attribute is NOT supported by filesystem)
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Setting file as hidden");
conn.setHidden(true);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden + " (should have no effect)");
passed = isHidden==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isHidden() on a file (hidden attribute is NOT supported by filesystem)", passed);
}
/**
* Tests isHidden() on a directory (hidden attribute is NOT supported by filesystem)
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Setting directory as hidden");
conn.setHidden(true);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden + " (should have no effect)");
passed = isHidden==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isHidden() on a file (hidden attribute is NOT supported by filesystem)", passed);
}
/**
* isHidden() throws ConnectionClosedException if connection is closed
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Closing connection");
conn.close();
try {
addOperationDesc("Attempting to call isHidden() on a closed connection");
boolean isHidden = conn.isHidden();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("isHidden() throws ConnectionClosedException if connection is closed", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0008() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
conn.isHidden();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests isHidden() in Connector.READ mode
*/
public void test0009() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() call returned " + isHidden);
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isHidden() in Connector.READ mode", passed);
}
/**
* Tests isHidden() on a non-existent file
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
passed = isHidden==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("isHidden() returns false for a non-existent file", passed);
}
/**
* Tests isHidden() on a non-existent file (hidden attribute is NOT supported by filesystem)
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
passed = isHidden==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("isHidden() returns false for a non-existent file (hidden attribute is NOT supported by filesystem)", passed);
}
/**
* Tests isHidden() on a non-existent directory
*/
public void test0012() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
passed = isHidden==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("isHidden() returns false for a non-existent directory", passed);
}
/**
* Tests isHidden() on a non-existent directory (hidden attribute is NOT supported by filesystem)
*/
public void test0013() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
passed = isHidden==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("isHidden() returns false for a non-existent directory (hidden attribute is NOT supported by filesystem)", passed);
}
/**
* Tests isHidden() on a non-existent file system
*/
public void test0014() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() call returned " + isHidden);
passed = isHidden==false;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isHidden() on a non-existent file system", passed);
}
/**
* Tests isHidden() on a non-existent host
*/
public void test0015() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() call returned " + isHidden);
passed = isHidden==false;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests isHidden() on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,336 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class LastModified extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
}
/*
* Tests lastModified() on a file
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
long startTime = System.currentTimeMillis();
ensureFileExists(conn);
long endTime = System.currentTimeMillis();
// round startTime down to nearest minute
startTime -= startTime % 60000;
// round endTime up to nearest minute
endTime += 60000 - (endTime % 60000);
long modifyTime = conn.lastModified();
addOperationDesc("lastModified() returned " + modifyTime);
passed = modifyTime >= startTime && modifyTime <= endTime;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests lastModified() on a file", passed);
}
/*
* Tests lastModified() on a file (modification date is NOT supported by filesystem)
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
long modifyTime = conn.lastModified();
addOperationDesc("lastModified() returned " + modifyTime);
passed = modifyTime == 0;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests lastModified() on a file (modification date is NOT supported by filesystem)", passed);
}
/*
* Tests lastModified() on a directory
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
long startTime = System.currentTimeMillis();
ensureDirExists(conn);
long endTime = System.currentTimeMillis();
// round startTime down to nearest minute
startTime -= startTime % 60000;
// round endTime up to nearest minute
endTime += 60000 - (endTime % 60000);
long modifyTime = conn.lastModified();
addOperationDesc("lastModified() returned " + modifyTime);
passed = modifyTime >= startTime && modifyTime <= endTime;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests lastModified() on a directory", passed);
}
/*
* Tests lastModified() on a directory (modification date is NOT supported by filesystem)
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
long modifyTime = conn.lastModified();
addOperationDesc("lastModified() returned " + modifyTime);
passed = modifyTime == 0;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests lastModified() on a directory (modification date is NOT supported by filesystem)", passed);
}
/**
* ConnectionClosedException thrown if invoked on a closed connection
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
conn.close();
try {
conn.lastModified();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if invoked on a closed connection", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0006() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
conn.lastModified();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests lastModified() in Connector.READ mode
*/
public void test0007() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
long lastModified = conn.lastModified();
addOperationDesc("lastModified() call returned " + lastModified);
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests lastModified() in Connector.READ mode", passed);
}
/*
* Tests lastModified() on a non-existent file
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
long modifyTime = conn.lastModified();
addOperationDesc("lastModified() returned " + modifyTime);
passed = modifyTime == 0;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests lastModified() on a non-existent file", passed);
}
/**
* Tests lastModified() on a non-existent file system
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"testdir/", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
long lastModified = conn.lastModified();
addOperationDesc("lastModified() call returned " + lastModified);
passed = lastModified==0;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests lastModified() on a non-existent file system", passed);
}
/**
* Tests lastModified() on a non-existent host
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"testdir/", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
long lastModified = conn.lastModified();
addOperationDesc("lastModified() call returned " + lastModified);
passed = lastModified==0;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests lastModified() on a non-existent host", passed);
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,334 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class Mkdir extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
}
/*
* mkdir() creates a new directory
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
addOperationDesc("Creating directory");
conn.mkdir();
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists == true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("mkdir() creates a new directory", passed);
}
/*
* IOException thrown if parent directory does not exist
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/subdir/", Connector.READ_WRITE);
addOperationDesc("Deleting directory: " + conn1.getURL());
ensureNotExists(conn1);
addOperationDesc("Attempting to create directory: " + conn2.getURL());
try {
conn2.mkdir();
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if parent directory does not exist", passed);
}
/*
* IOException thrown if target is a file
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Attempting to mkdir file");
try {
conn.mkdir();
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
boolean exists= conn.exists();
passed = exists==true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if target is a file", passed);
}
/*
* IOException thrown if target is an existing directory
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Attempting to mkdir()");
try {
conn.mkdir();
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
boolean exists= conn.exists();
passed = exists==true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if target is an existing directory", passed);
}
/*
* ConnectionClosedException thrown if connection is closed
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
addOperationDesc("Closing connection");
conn.close();
try {
addOperationDesc("Attempting to call mkdir() on closed connection");
conn.mkdir();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if invoked on a closed connection", passed);
}
/*
* IllegalModeException thrown for connections opened in Connector.READ mode
*/
public void test0006() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ);
try {
try {
conn.mkdir();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/*
* Tests mkdir() in Connector.WRITE mode
*/
public void test0007() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = null;
FileConnection conn2 = null;
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn2);
addOperationDesc("Creating directory");
conn.mkdir();
boolean exists = conn2.exists();
addOperationDesc("exists() returned " + exists);
passed = exists==true;
} finally {
if (conn != null) conn.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests mkdir() in Connector.WRITE mode", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.mkdir();
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.mkdir();
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,176 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class Open extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
}
/**
* Tests Connector.open() with a valid file url in Connector.READ_WRITE mode
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
passed = true;
conn.close();
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests Connector.open() with a valid file url in Connector.READ_WRITE mode", passed);
}
/**
* Tests Connector.open() with a valid file url in Connector.READ mode
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
passed = true;
conn.close();
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests Connector.open() with a valid file url in Connector.READ mode", passed);
}
/**
* Tests Connector.open() with a valid file url in Connector.WRITE mode
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
passed = true;
conn.close();
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests Connector.open() with a valid file url in Connector.WRITE mode", passed);
}
/**
* Tests Connector.open() with a relative file url
*/
public void test0004() {
boolean passed = false;
try {
String url1 = "file:///..";
try {
FileConnection conn = (FileConnection)Connector.open(url1, Connector.READ_WRITE);
passed = false;
addOperationDesc("No IllegalArgumentException thrown for url " + url1);
conn.close();
} catch (IllegalArgumentException e) {
passed = true;
addOperationDesc("Expected IllegalArgumentException thrown for file url " + url1);
}
String url2 = "file:///.";
try {
FileConnection conn = (FileConnection)Connector.open(url2, Connector.READ_WRITE);
passed = false;
addOperationDesc("No IllegalArgumentException thrown for url " + url2);
conn.close();
} catch (IllegalArgumentException e) {
passed = true;
addOperationDesc("Expected IllegalArgumentException thrown for file url " + url2);
}
String url3 = "file://"+getTestPath()+"test/..";
try {
FileConnection conn = (FileConnection)Connector.open(url1, Connector.READ_WRITE);
passed = false;
addOperationDesc("No IllegalArgumentException thrown for url " + url3);
conn.close();
} catch (IllegalArgumentException e) {
passed = true;
addOperationDesc("Expected IllegalArgumentException thrown for file url " + url3);
}
String url4 = "file://"+getTestPath()+"test/.";
try {
FileConnection conn = (FileConnection)Connector.open(url4, Connector.READ_WRITE);
passed = false;
addOperationDesc("No IllegalArgumentException thrown for url " + url4);
conn.close();
} catch (IllegalArgumentException e) {
passed = true;
addOperationDesc("Expected IllegalArgumentException thrown for file url " + url4);
}
String url5 = "file://"+getTestPath()+"test/../test";
try {
FileConnection conn = (FileConnection)Connector.open(url5, Connector.READ_WRITE);
passed = false;
addOperationDesc("No IllegalArgumentException thrown for url " + url5);
conn.close();
} catch (IllegalArgumentException e) {
passed = true;
addOperationDesc("Expected IllegalArgumentException thrown for file url " + url5);
}
String url6 = "file://"+getTestPath()+"test/./test";
try {
FileConnection conn = (FileConnection)Connector.open(url6, Connector.READ_WRITE);
passed = false;
addOperationDesc("No IllegalArgumentException thrown for url " + url6);
conn.close();
} catch (IllegalArgumentException e) {
passed = true;
addOperationDesc("Expected IllegalArgumentException thrown for file url " + url6);
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests Connector.open() with a relative file", passed);
}
/**
* Tests Connector.open() with a file url containing '\' character
*/
public void test0005() {
boolean passed = false;
try {
String url = "file://"+getTestPath()+"test\\test";
try {
FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
passed = false;
addOperationDesc("No IllegalArgumentException thrown for url " + url);
conn.close();
} catch (IllegalArgumentException e) {
passed = true;
addOperationDesc("Expected IllegalArgumentException thrown for url " + url);
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests Connector.open() with a file url containing '\' character", passed);
}
}

Просмотреть файл

@ -0,0 +1,399 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class OpenDataInputStream extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
}
/**
* Tests openDataInputStream()
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
DataInputStream is = null;
DataOutputStream os = null;
try {
addOperationDesc("Writing UTF string to output stream: foobar");
os = conn.openDataOutputStream();
os.writeUTF("foobar");
os.close();
os = null;
is = conn.openDataInputStream();
String result = is.readUTF();
addOperationDesc("Reading UTF string from input stream: " + result);
passed = result.equals("foobar");
} finally {
if (is != null) is.close();
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openDataInputStream()", passed);
}
/**
* IOException thrown if invoked on a directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Attempting to open stream on directory");
try {
InputStream is = conn.openDataInputStream();
addOperationDesc("No IOException thrown");
passed = false;
is.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a directory", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0003() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
DataInputStream is = conn.openDataInputStream();
addOperationDesc("No IllegalModeException thrown");
passed = false;
is.close();
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests openDataInputStream() in Connector.READ mode
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
DataInputStream is = null;
DataOutputStream os = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
addOperationDesc("Opening connection in READ mode");
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
addOperationDesc("Writing UTF string to output stream: foobar");
os = conn1.openDataOutputStream();
os.writeUTF("foobar");
os.close();
os=null;
conn1.close();
conn1=null;
is = conn2.openDataInputStream();
String result = is.readUTF();
addOperationDesc("Reading UTF string from input stream: " + result);
passed = result.equals("foobar");
} finally {
if (is != null) is.close();
if (os != null) os.close();
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openDataInputStream() in Connector.READ mode", passed);
}
/**
* IOException thrown if multiple input streams opened
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
InputStream is = null;
DataInputStream dis = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening first input stream");
// try for an InputStream to make sure that they are considered the same
is = conn.openInputStream();
try {
dis = conn.openDataInputStream();
addOperationDesc("No IOException thrown");
passed = false;
dis.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
if (is!=null) is.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if multiple input streams opened", passed);
}
/**
* IOException thrown if the file the connection is opened to does not yet exist
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
DataInputStream dis = conn.openDataInputStream();
addOperationDesc("No IOException thrown");
dis.close();
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if the file the connection is opened to does not yet exist", passed);
}
/**
* Streams can be opened and closed more than once on a connection
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
InputStream stream =null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening stream");
stream = conn.openDataInputStream();
addOperationDesc("Closing stream");
stream.close();
stream = null;
addOperationDesc("Opening stream");
stream = conn.openDataInputStream();
addOperationDesc("Closing stream");
stream.close();
stream =null;
passed = true;
} finally {
if (stream!=null) stream.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Streams can be opened and closed more than once on a connection", passed);
}
/**
* IOException thrown if connection is closed
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Closing connection");
conn.close();
try {
addOperationDesc("Attempting to call openDataInputStream() on closed connection");
DataInputStream dis = conn.openDataInputStream();
addOperationDesc("No IOException thrown");
passed = false;
dis.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a closed connection", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
DataInputStream dis = conn.openDataInputStream();
addOperationDesc("No IOException thrown");
passed = false;
dis.close();
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
DataInputStream dis = conn.openDataInputStream();
addOperationDesc("No IOException thrown");
passed = false;
dis.close();
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,440 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class OpenDataOutputStream extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
}
/**
* Tests openDataOutputStream()
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
DataOutputStream os = null;
try {
os = conn.openDataOutputStream();
long fileSize1 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
addOperationDesc("Writing int to output stream");
os.writeInt(2);
addOperationDesc("Closing output stream");
os.close();
os = null;
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
passed = fileSize2>fileSize1;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openDataOutputStream()", passed);
}
/**
* IOException thrown if invoked on a directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Attempting to open stream on directory");
try {
OutputStream os = conn.openDataOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
os.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a directory", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.READ mode
*/
public void test0003() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
try {
DataOutputStream os = conn.openDataOutputStream();
addOperationDesc("No IllegalModeException thrown");
passed = false;
os.close();
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.READ mode", passed);
}
/**
* Tests openDataOutputStream() in Connector.WRITE mode
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
DataOutputStream os = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
addOperationDesc("Opening connection in WRITE mode");
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
os = conn2.openDataOutputStream();
long fileSize1 = conn1.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
addOperationDesc("Writing int to output stream");
os.writeInt(2);
addOperationDesc("Closing output stream");
os.close();
os = null;
long fileSize2 = conn1.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
passed = fileSize2>fileSize1;
} finally {
if (os != null) os.close();
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openDataOutputStream() in Connector.WRITE mode", passed);
}
/**
* IOException thrown if multiple output streams opened
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os0 = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening first input stream");
// try for an OutputStream to make sure that they are considered the same
os0 = conn.openOutputStream();
try {
DataOutputStream dos = conn.openDataOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
dos.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
if (os0!=null) os0.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if multiple output streams opened", passed);
}
/**
* IOException thrown if the file the connection is opened to does not yet exist
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
DataOutputStream os = conn.openDataOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
os.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if the file the connection is opened to does not yet exist", passed);
}
/**
* Streams can be opened and closed more than once on a connection
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
DataOutputStream stream = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening stream");
stream = conn.openDataOutputStream();
addOperationDesc("Closing stream");
stream.close();
stream = null;
addOperationDesc("Opening stream");
stream = conn.openDataOutputStream();
addOperationDesc("Closing stream");
stream.close();
stream = null;
passed = true;
} finally {
if (stream!=null) stream.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Streams can be opened and closed more than once on a connection", passed);
}
/**
* IOException thrown if connection is closed
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Closing connection");
conn.close();
try {
addOperationDesc("Attempting to call openDataOutputStream() on closed connection");
DataOutputStream os = conn.openDataOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
os.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a closed connection", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
DataOutputStream dos = conn.openDataOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
dos.close();
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
DataOutputStream dos = conn.openDataOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
dos.close();
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
/**
* Tests if the DataOutputStream returned from openDataOutputStream() updates the file immediately when flush() is called.
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
DataOutputStream os = null;
try {
long fileSize1 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
os = conn.openDataOutputStream();
addOperationDesc("Writing 1024 bytes to output stream");
os.write(new byte[1024]);
os.flush();
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
passed = fileSize2==1024;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests if the DataOutputStream returned from openDataOutputStream() updates the file immediately when flush() is called", passed);
}
}

Просмотреть файл

@ -0,0 +1,396 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class OpenInputStream extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
}
/**
* Tests openInputStream()
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
InputStream is = null;
OutputStream os = null;
try {
addOperationDesc("Writing byte to output stream: 69");
os = conn.openOutputStream();
os.write(69);
os.flush();
is = conn.openInputStream();
int result = is.read();
addOperationDesc("Reading byte from input stream: " + result);
passed = result==69;
} finally {
if (is != null) is.close();
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openInputStream()", passed);
}
/**
* IOException thrown if invoked on a directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Attempting to open stream on directory");
try {
InputStream is = conn.openInputStream();
addOperationDesc("No IOException thrown");
passed = false;
is.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a directory", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0003() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
InputStream is = conn.openInputStream();
addOperationDesc("No IllegalModeException thrown");
passed = false;
is.close();
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests openInputStream() in Connector.READ mode
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
InputStream is = null;
OutputStream os = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
addOperationDesc("Opening connection in READ mode");
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
addOperationDesc("Writing byte to output stream: 69");
os = conn1.openOutputStream();
os.write(69);
os.close();
os=null;
conn1.close();
conn1=null;
is = conn2.openInputStream();
int result = is.read();
addOperationDesc("Reading byte from input stream: " + result);
passed = result==69;
} finally {
if (is != null) is.close();
if (os != null) os.close();
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openInputStream() in Connector.READ mode", passed);
}
/**
* IOException thrown if multiple input streams opened
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
InputStream is0 = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening first input stream");
is0 = conn.openInputStream();
try {
InputStream is = conn.openInputStream();
addOperationDesc("No IOException thrown");
passed = false;
is.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
if (is0!=null) is0.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if multiple input streams opened", passed);
}
/**
* IOException thrown if the file the connection is opened to does not yet exist
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
InputStream is = conn.openInputStream();
addOperationDesc("No IOException thrown");
passed = false;
is.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if the file the connection is opened to does not yet exist", passed);
}
/**
* Streams can be opened and closed more than once on a connection
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
InputStream stream = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening stream");
stream = conn.openInputStream();
addOperationDesc("Closing stream");
stream.close();
stream = null;
addOperationDesc("Opening stream");
stream = conn.openInputStream();
addOperationDesc("Closing stream");
stream.close();
stream = null;
passed = true;
} finally {
if (stream!=null) stream.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Streams can be opened and closed more than once on a connection", passed);
}
/*
* IOException thrown if connection is closed
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Closing connection");
conn.close();
try {
addOperationDesc("Attempting to call openInputStream() on closed connection");
InputStream is = conn.openInputStream();
addOperationDesc("No IOException thrown");
passed = false;
is.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a closed connection", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
InputStream is = conn.openInputStream();
addOperationDesc("No IOException thrown");
passed = false;
is.close();
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
InputStream is = conn.openInputStream();
addOperationDesc("No IOException thrown");
passed = false;
is.close();
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,443 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class OpenOutputStream extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
}
/**
* Tests openOutputStream()
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
OutputStream os = null;
try {
os = conn.openOutputStream();
long fileSize1 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
addOperationDesc("Writing byte to output stream");
os.write(3);
addOperationDesc("Closing output stream");
os.close();
os = null;
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
passed = fileSize2>fileSize1;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openOutputStream()", passed);
}
/**
* IOException thrown if invoked on a directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Attempting to open stream on directory");
try {
OutputStream os = conn.openOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
os.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a directory", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.READ mode
*/
public void test0003() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
try {
OutputStream os = conn.openOutputStream();
addOperationDesc("No IllegalModeException thrown");
passed = false;
os.close();
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.READ mode", passed);
}
/**
* Tests openOutputStream() in Connector.WRITE mode
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
OutputStream os = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
addOperationDesc("Opening connection in WRITE mode");
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
os = conn2.openOutputStream();
long fileSize1 = conn1.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
addOperationDesc("Writing byte to output stream");
os.write(3);
addOperationDesc("Closing output stream");
os.close();
os = null;
long fileSize2 = conn1.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
passed = fileSize2>fileSize1;
} finally {
if (os != null) os.close();
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openOutputStream() in Connector.WRITE mode", passed);
}
/**
* IOException thrown if multiple output streams opened
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os0 = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening first output stream");
os0 = conn.openOutputStream();
try {
OutputStream os = conn.openOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
os.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
if (os0!=null) os0.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if multiple output streams opened", passed);
}
/**
* IOException thrown if the file the connection is opened to does not yet exist
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
OutputStream os = conn.openOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
os.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if the file the connection is opened to does not yet exist", passed);
}
/**
* Streams can be opened and closed more than once on a connection calling openOutputStream()
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream stream = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening stream");
stream = conn.openOutputStream();
addOperationDesc("Closing stream");
stream.close();
stream = null;
addOperationDesc("Opening stream");
stream = conn.openOutputStream();
addOperationDesc("Closing stream");
stream.close();
stream = null;
passed = true;
} finally {
if (stream!=null) stream.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Streams can be opened and closed more than once on a connection calling openOutputStream()", passed);
}
/*
* IOException thrown if connection is closed
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Closing connection");
conn.close();
try {
addOperationDesc("Attempting to call openOutputStream() on closed connection");
OutputStream os = conn.openOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
os.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a closed connection", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
OutputStream os = conn.openOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
os.close();
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
OutputStream os = conn.openOutputStream();
addOperationDesc("No IOException thrown");
passed = false;
os.close();
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
/**
* Tests if the OutputStream returned from openOutputStream() updates the file immediately when flush() is called.
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
OutputStream os = null;
try {
long fileSize1 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
os = conn.openOutputStream();
addOperationDesc("Writing 1024 bytes to output stream");
os.write(new byte[1024]);
os.flush();
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
passed = fileSize2==1024;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests if the OutputStream returned from openOutputStream() updates the file immediately when flush() is called", passed);
}
}

Просмотреть файл

@ -0,0 +1,559 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class OpenOutputStream_Long extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
if (isTestValid("test0012")) test0012();
if (isTestValid("test0013")) test0013();
}
/**
* Tests openOutputStream(long)
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
OutputStream os = null;
try {
long fileSize1 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
addOperationDesc("Opening output stream at offset " + fileSize1);
os = conn.openOutputStream(fileSize1);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
addOperationDesc("Opening output stream at offset " + (fileSize2-1));
os = conn.openOutputStream(fileSize2-1);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize3 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize3);
passed = fileSize2==fileSize1+2 && fileSize3==fileSize2+1;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openOutputStream(long)", passed);
}
/**
* IOException thrown from openOutputStream(long) if invoked on a directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Attempting to open stream on directory");
try {
OutputStream os = conn.openOutputStream(0);
addOperationDesc("No IOException thrown");
passed = false;
os.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown from openOutputStream(long) if invoked on a directory", passed);
}
/**
* IllegalModeException thrown from openOutputStream(long) for connections opened in Connector.READ mode
*/
public void test0003() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
try {
OutputStream os = conn.openOutputStream(0);
addOperationDesc("No IllegalModeException thrown");
passed = false;
os.close();
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown from openOutputStream(long) for connections opened in Connector.READ mode", passed);
}
/**
* Tests openOutputStream(long) in Connector.WRITE mode
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
OutputStream os = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
addOperationDesc("Opening connection in WRITE mode");
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
os = conn2.openOutputStream(0);
long fileSize1 = conn1.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
addOperationDesc("Writing byte to output stream");
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize2 = conn1.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
passed = fileSize2>fileSize1;
} finally {
if (os != null) os.close();
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openOutputStream(long) in Connector.WRITE mode", passed);
}
/**
* IOException thrown from openOutputStream(long) if multiple output streams opened
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os0 = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening first output stream");
os0= conn.openOutputStream(0);
try {
OutputStream os = conn.openOutputStream(0);
addOperationDesc("No IOException thrown");
passed = false;
os.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
if (os0!=null) os0.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown from openOutputStream(long) if multiple output streams opened", passed);
}
/**
* IOException thrown from openOutputStream(long) if the file the connection is opened to does not yet exist
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
OutputStream os = conn.openOutputStream(0);
addOperationDesc("No IOException thrown");
passed = false;
os.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown from openOutputStream(long) if the file the connection is opened to does not yet exist", passed);
}
/**
* Streams can be opened and closed more than once on a connection calling openOutputStream(long)
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream stream = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Opening stream");
stream = conn.openOutputStream(0);
addOperationDesc("Closing stream");
stream.close();
stream = null;
addOperationDesc("Opening stream");
stream = conn.openOutputStream(0);
addOperationDesc("Closing stream");
stream.close();
stream = null;
passed = true;
} finally {
if (stream!=null) stream.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Streams can be opened and closed more than once on a connection calling openOutputStream(long)", passed);
}
/*
* IOException thrown if connection is closed
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Closing connection");
conn.close();
try {
addOperationDesc("Attempting to call openOutputStream(long) on closed connection");
OutputStream os = conn.openOutputStream(0);
addOperationDesc("No IOException thrown");
passed = false;
os.close();
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a closed connection", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
OutputStream os = conn.openOutputStream(0);
addOperationDesc("No IOException thrown");
passed = false;
os.close();
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
OutputStream os = conn.openOutputStream(0);
addOperationDesc("No IOException thrown");
passed = false;
os.close();
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
/**
* Tests openOutputStream(long) with an offset equal to the fileSize
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
OutputStream os = null;
try {
long fileSize1 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
addOperationDesc("Opening output stream at offset " + fileSize1);
os = conn.openOutputStream(fileSize1);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
addOperationDesc("Opening output stream at offset " + fileSize2);
os = conn.openOutputStream(fileSize2);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize3 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize3);
passed = fileSize2==fileSize1+2 && fileSize3==fileSize2+2;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openOutputStream(long) with an offset larger than fileSize", passed);
}
/**
* Tests openOutputStream(long) with an offset larger than fileSize
*/
public void test0012() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
OutputStream os = null;
try {
long fileSize1 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
addOperationDesc("Opening output stream at offset " + (fileSize1+3));
os = conn.openOutputStream(fileSize1+3);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
addOperationDesc("Opening output stream at offset " + (fileSize2+7));
os = conn.openOutputStream(fileSize2+7);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize3 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize3);
passed = fileSize2==fileSize1+2 && fileSize3==fileSize2+2;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openOutputStream(long) with an offset larger than fileSize", passed);
}
/**
* Tests if the OutputStream returned from openOutputStream(long) updates the file immediately when flush() is called.
*/
public void test0013() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
OutputStream os = null;
try {
long fileSize0 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize0);
os = conn.openOutputStream(0);
addOperationDesc("Writing 64 bytes to output stream");
os.write(new byte[64]);
os.flush();
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
passed = fileSize2==64;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests if the OutputStream returned from openOutputStream(long) updates the file immediately when flush() is called", passed);
}
}

Просмотреть файл

@ -0,0 +1,28 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class PackageDiscovery extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
}
/**
* Tests that the microedition.io.file.FileConnection.version system property is set
*/
public void test0001() {
String value = System.getProperty("microedition.io.file.FileConnection.version");
addOperationDesc("microedition.io.file.FileConnection.version=" + value);
boolean passed = value != null && value.equals("1.0");
assertTrueWithLog("Tests that the microedition.io.file.FileConnection.version system property is set to 1.0", passed);
}
}

Просмотреть файл

@ -0,0 +1,805 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class Rename extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
if (isTestValid("test0012")) test0012();
if (isTestValid("test0013")) test0013();
if (isTestValid("test0014")) test0014();
if (isTestValid("test0015")) test0015();
if (isTestValid("test0016")) test0016();
if (isTestValid("test0017")) test0017();
if (isTestValid("test0018")) test0018();
if (isTestValid("test0019")) test0019();
}
/**
* Tests rename() on a file
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test2", Connector.READ_WRITE);
// make sure the existing target does exist already
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
// make sure the new target does not exist already
addOperationDesc("Deleting file: " + conn2.getURL());
ensureNotExists(conn2);
addOperationDesc("renaming " + conn1.getURL() + " to " + conn2.getURL());
conn1.rename("test2");
passed = conn2.exists();
addOperationDesc("exists() on " + conn2.getURL() + " returned " + passed);
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests rename() on a file", passed);
}
/**
* Tests rename() on a directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir1/", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir2/", Connector.READ_WRITE);
// make sure the existing target does exist already
addOperationDesc("Creating directory: " + conn1.getURL());
ensureDirExists(conn1);
// make sure the new target does not exist already
addOperationDesc("Deleting directory: " + conn2.getURL());
ensureNotExists(conn2);
addOperationDesc("renaming " + conn1.getURL() + " to " + conn2.getURL());
conn1.rename("testdir2");
passed = conn2.exists();
addOperationDesc("exists() on " + conn2.getURL() + " returned " + passed);
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests rename() on a directory", passed);
}
/**
* Tests that file connection target before rename() no longer exists after method invocation
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test2", Connector.READ_WRITE);
// make sure the existing target does exist already
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
// make sure the new target does not exist already
addOperationDesc("Deleting file: " + conn2.getURL());
ensureNotExists(conn2);
addOperationDesc("renaming " + conn1.getURL() + " to " + conn2.getURL());
conn1.rename("test2");
// reopen on initial file
conn1.close();
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
boolean conn1Exists = conn1.exists();
addOperationDesc("exists() on " + conn1.getURL() + " returned " + conn1Exists);
passed = conn1Exists==false;
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests that file connection target before rename() no longer exists after method invocation", passed);
}
/**
* Tests that the file connection target changes after rename() call
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test2", Connector.READ_WRITE);
// make sure the existing target does exist already
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
// make sure the new target does not exist already
addOperationDesc("Deleting file: " + conn2.getURL());
ensureNotExists(conn2);
addOperationDesc("renaming " + conn1.getURL() + " to " + conn2.getURL());
conn1.rename("test2");
String conn1URL = conn1.getURL();
addOperationDesc("getURL() after rename is " + conn1.getURL());
passed = conn1URL.equals(conn2.getURL());
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests that the file connection target changes after rename() call", passed);
}
/**
* Input stream is closed after rename()
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
InputStream is = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test2", Connector.READ_WRITE);
// make sure the existing target does exist already
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
// make sure the new target does not exist already
addOperationDesc("Deleting file: " + conn2.getURL());
ensureNotExists(conn2);
addOperationDesc("opening input stream on: " + conn1.getURL());
is = conn1.openInputStream();
addOperationDesc("renaming " + conn1.getURL() + " to " + conn2.getURL());
conn1.rename("test2");
addOperationDesc("Attempting to read from old input stream");
try {
is.read();
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
}
} finally {
if (is!=null) is.close();
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Input stream is closed after rename()", passed);
}
/**
* Output stream is closed after rename()
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
OutputStream os = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test2", Connector.READ_WRITE);
// make sure the existing target does exist already
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
// make sure the new target does not exist already
addOperationDesc("Deleting file: " + conn2.getURL());
ensureNotExists(conn2);
addOperationDesc("opening output stream on: " + conn1.getURL());
os = conn1.openOutputStream();
addOperationDesc("renaming " + conn1.getURL() + " to " + conn2.getURL());
conn1.rename("test2");
addOperationDesc("Attempting to write to the old output stream");
try {
os.write(0);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
}
} finally {
if (os!=null) os.close();
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Output stream is closed after rename()", passed);
}
/**
* Output stream was flushed after rename()
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
OutputStream os = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test2", Connector.READ_WRITE);
// make sure the existing target does exist already
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
// make sure the new target does not exist already
addOperationDesc("Deleting file: " + conn2.getURL());
ensureNotExists(conn2);
long startSize = conn1.fileSize();
addOperationDesc("fileSize() of " + conn1.getURL() + " is " + startSize);
addOperationDesc("opening output stream on: " + conn1.getURL());
os = conn1.openOutputStream();
addOperationDesc("writing 1 byte");
os.write(0);
addOperationDesc("renaming " + conn1.getURL() + " to " + conn2.getURL());
conn1.rename("test2");
long endSize = conn2.fileSize();
addOperationDesc("fileSize() of " + conn2.getURL() + " is " + endSize);
passed = startSize==(endSize-1);
} finally {
if (os!=null) os.close();
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Output stream was flushed after rename()", passed);
}
/**
* ConnectionClosedException thrown if connection is closed
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
conn.close();
try {
conn.rename("test2");
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if connection is closed", passed);
}
/**
* IOException thrown if connection target does not exist
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test2", Connector.READ_WRITE);
// make sure the existing target does not exist already
addOperationDesc("Deleting file: " + conn1.getURL());
ensureNotExists(conn1);
// make sure the new target does not exist already
addOperationDesc("Deleting file: " + conn2.getURL());
ensureNotExists(conn2);
addOperationDesc("attempting to rename " + conn1.getURL() + " to " + conn2.getURL());
try {
conn1.rename("test2");
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if connection target does not exist", passed);
}
/**
* IOException thrown if the new target already exists
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test2", Connector.READ_WRITE);
// make sure the existing target does not exist already
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
// make sure the new target does exist already
addOperationDesc("Creating file: " + conn2.getURL());
ensureFileExists(conn2);
addOperationDesc("attempting to rename " + conn1.getURL() + " to " + conn2.getURL());
try {
conn1.rename("test2");
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if the new target already exists", passed);
}
/**
* IllegalArgumentException thrown if new target contains path specification
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn1 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
// make sure the existing target does not exist already
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
addOperationDesc("attempting to rename " + conn1.getURL() + " to " + "../test1");
try {
conn1.rename("../test1");
addOperationDesc("No IllegalArgumentException thrown");
passed = false;
} catch (IllegalArgumentException e) {
addOperationDesc("Expected IllegalArgumentException thrown");
passed = true;
}
} finally {
if (conn1 != null) conn1.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalArgumentException thrown if new target contains path specification", passed);
}
/**
* IOException thrown if new target contains invalid filename characters
*/
public void test0012() {
boolean passed = false;
try {
FileConnection conn1 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
// make sure the existing target does not exist already
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
addOperationDesc("attempting to rename " + conn1.getURL() + " to " + "te:st");
try {
conn1.rename("te:st");
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
if (conn1 != null) conn1.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if new target contains invalid filename characters", passed);
}
/**
* NullPointerException thrown if newName is null
*/
public void test0013() {
boolean passed = false;
try {
FileConnection conn1 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
// make sure the existing target does not exist already
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
addOperationDesc("attempting to rename " + conn1.getURL() + " with a null newName");
try {
conn1.rename(null);
addOperationDesc("No NullPointerException thrown");
passed = false;
} catch (NullPointerException e) {
addOperationDesc("Expected NullPointerException thrown");
passed = true;
}
} finally {
if (conn1 != null) conn1.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("NullPointerException thrown if newName is null", passed);
}
/**
* rename() throws IllegalModeException for connections opened in Connector.READ mode
*/
public void test0014() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
try {
conn.rename("test1");
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("rename() throws IllegalModeException for connections opened in Connector.READ mode", passed);
}
/**
* Tests rename() in Connector.WRITE mode
*/
public void test0015() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test2", Connector.READ_WRITE);
// make sure the existing target does exist already
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
// make sure the new target does not exist already
addOperationDesc("Deleting file: " + conn2.getURL());
ensureNotExists(conn2);
conn1.close();
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test1", Connector.WRITE);
addOperationDesc("renaming " + conn1.getURL() + " to " + conn2.getURL());
conn1.rename("test2");
passed = conn2.exists();
addOperationDesc("exists() on " + conn2.getURL() + " returned " + passed);
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests rename() in Connector.WRITE mode", passed);
}
/**
* Tests rename() on a file name in escaped form.
*/
public void test0016() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+ getTestPath() + "test", Connector.READ_WRITE);
String urlString = "file://"+getTestPath()+"a file";
conn2 = (FileConnection)Connector.open(urlString, Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
addOperationDesc("Deleting file: " + urlString);
ensureNotExists(conn2);
String fileName = "a%20file";
addOperationDesc("renaming to file: " + fileName);
conn1.rename(fileName);
String newUrl = conn1.getURL();
addOperationDesc("getURL() returned: " + newUrl);
String newPath = conn1.getPath();
addOperationDesc("getPath() returned: " + newPath);
String newName = conn1.getName();
addOperationDesc("getName() returned: " + newName);
passed = conn1.exists() && conn2.exists() &&
newUrl.equals(conn2.getURL()) &&
newPath.equals(conn2.getPath()) &&
newName.equals(conn2.getName());
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Test rename() on a file name in escaped form.", passed);
}
/**
* Tests rename() on a file name in unescaped form.
*/
public void test0017() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+ getTestPath() + "test", Connector.READ_WRITE);
String urlString = "file://"+getTestPath()+"a%20file";
conn2 = (FileConnection)Connector.open(urlString, Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn1.getURL());
ensureFileExists(conn1);
addOperationDesc("Deleting file: " + urlString);
ensureNotExists(conn2);
String fileName = "a file";
addOperationDesc("renaming to file: " + fileName);
conn1.rename(fileName);
String newUrl = conn1.getURL();
addOperationDesc("getURL() returned: " + newUrl);
String newPath = conn1.getPath();
addOperationDesc("getPath() returned: " + newPath);
String newName = conn1.getName();
addOperationDesc("getName() returned: " + newName);
passed = conn1.exists() && conn2.exists() &&
newUrl.equals(conn2.getURL()) &&
newPath.equals(conn2.getPath()) &&
newName.equals(conn2.getName());
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Test rename() on a file name in unescaped form.", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0018() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.rename("newfileName");
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0019() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.rename("newfileName");
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,547 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class SetFileConnection extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
if (isTestValid("test0013")) test0013();
if (isTestValid("test0014")) test0014();
if (isTestValid("test0015")) test0015();
if (isTestValid("test0016")) test0016();
}
/**
* Traverse to parent directory
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath(), Connector.READ_WRITE);
addOperationDesc("Opened the file connection on url: " + conn1.getURL());
addOperationDesc("Creating directory: " + conn1.getURL());
ensureDirExists(conn1);
addOperationDesc("Setting the file connection to parent directory");
conn1.setFileConnection("..");
String newUrl = conn1.getURL();
addOperationDesc("getURL() returned: " + newUrl);
passed = newUrl.equals(conn2.getURL());
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Traverse to parent directory", passed);
}
/**
* Traverse to a subdirectory
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath(), Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Opened the file connection on url: " + conn1.getURL());
addOperationDesc("Creating subdirectory: " + conn2.getURL());
ensureDirExists(conn2);
addOperationDesc("Setting the file connection to subdirectory");
conn1.setFileConnection("testdir/");
String newUrl = conn1.getURL();
addOperationDesc("getURL() returned: " + newUrl);
passed = newUrl.equals(conn2.getURL());
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Traverse to subdirectory", passed);
}
/**
* Traverse to a file
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath(), Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Opened the file connection on url: " + conn1.getURL());
addOperationDesc("Creating file: " + conn2.getURL());
ensureFileExists(conn2);
addOperationDesc("setting the file connection to file");
conn1.setFileConnection("test");
String newUrl = conn1.getURL();
addOperationDesc("getURL() returned: " + newUrl);
passed = newUrl.equals(conn2.getURL());
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Traverse to a file", passed);
}
/**
* IOException thrown if connection's target is a file
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Opened the file connection on a file: " + conn.getURL());
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
try {
addOperationDesc("Attempting to set the file connection to the parent directory");
conn.setFileConnection("..");
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if connection's target is a file", passed);
}
/**
* IllegalArgumentException thrown if new target does not exist
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Opened the file connection on url: " + conn.getURL());
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
try {
addOperationDesc("Attempting to set the file connection to a non-existent file");
conn.setFileConnection("noexist");
addOperationDesc("No IllegalArgumentException thrown");
passed = false;
} catch (IllegalArgumentException e) {
addOperationDesc("Expected IllegalArgumentException thrown");
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalArgumentException thrown if new target does not exist", passed);
}
/**
* IllegalArgumentException thrown if new target contains path specification
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
try {
conn.setFileConnection("../testdir/");
addOperationDesc("No IllegalArgumentException thrown");
passed = false;
} catch (IllegalArgumentException e) {
addOperationDesc("Expected IllegalArgumentException thrown");
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalArgumentException thrown if new target contains path specification", passed);
}
/**
* IOException thrown if new target contains invalid filename characters
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
try {
conn.setFileConnection("te:st");
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if new target contains invalid filename characters", passed);
}
/**
* NullPointerException thrown if newFile is null
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
try {
conn.setFileConnection(null);
addOperationDesc("No NullPointerException thrown");
passed = false;
} catch (NullPointerException e) {
addOperationDesc("Expected NullPointerException thrown");
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("NullPointerException thrown if newFile is null", passed);
}
/**
* ConnectionClosedException thrown if connection is closed
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
conn.close();
try {
conn.setFileConnection("..");
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if connection is closed", passed);
}
/**
* Security mode is preserved for new target
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn1 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn1.getURL());
ensureDirExists(conn1);
addOperationDesc("opening connection in READ_WRITE mode");
// already done
addOperationDesc("traversing to parent directory");
conn1.setFileConnection("..");
addOperationDesc("attempting read operation");
conn1.canRead();
addOperationDesc("attempting write operation");
conn1.setReadable(true);
conn1.close();
addOperationDesc("opening connection in READ mode");
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ);
addOperationDesc("traversing to parent directory");
conn1.setFileConnection("..");
addOperationDesc("attempting read operation");
conn1.canRead();
addOperationDesc("attempting write operation");
try {
conn1.setReadable(true);
addOperationDesc("No IllegalModeException thrown");
passed = false;
return;
} catch (IllegalModeException e) {
addOperationDesc("Expected IllegalModeException thrown");
}
conn1.close();
addOperationDesc("opening connection in WRITE mode");
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.WRITE);
addOperationDesc("traversing to parent directory");
conn1.setFileConnection("..");
addOperationDesc("attempting read operation");
try {
conn1.canRead();
addOperationDesc("No IllegalModeException thrown");
passed = false;
return;
} catch (IllegalModeException e) {
addOperationDesc("Expected IllegalModeException thrown");
}
addOperationDesc("attempting write operation");
conn1.setReadable(true);
conn1.close();
passed = true;
} finally {
conn1.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Traverse to parent directory", passed);
}
private boolean isSameFile(FileConnection fc1, FileConnection fc2) {
return fc1.getPath().equals(fc2.getPath()) && fc1.getName().equals(fc2.getName());
}
/**
* Traverse to a file name that is in unescaped form.
*/
public void test0013() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
String urlString = "file://"+getTestPath()+"a%20file";
conn1 = (FileConnection)Connector.open("file://"+getTestPath(), Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open(urlString, Connector.READ_WRITE);
addOperationDesc("Opened the file connection on url: " + conn1.getURL());
addOperationDesc("Creating file: " + urlString);
ensureFileExists(conn2);
String fileName ="a file";
addOperationDesc("setting the file connection to file:" + fileName );
conn1.setFileConnection(fileName);
String newUrl = conn1.getURL();
addOperationDesc("getURL() returned: " + newUrl);
String newPath = conn1.getPath();
addOperationDesc("getPath() returned: " + newPath);
String newName = conn1.getName();
addOperationDesc("getName() returned: " + newName);
passed = conn1.exists() &&
newUrl.equals(conn2.getURL()) &&
newPath.equals(conn2.getPath()) &&
newName.equals(conn2.getName());
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Traverse to a file name that is in unescaped form.", passed);
}
/**
* IOException thrown if connection is opened on a non-existent directory
*/
public void test0014() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Opened the file connection on url: " + conn.getURL());
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
try {
addOperationDesc("Attempting to set the file connection to a new file");
conn.setFileConnection("newFileName");
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if connection is opened on a non-existent directory", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0015() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.setFileConnection("newFileName");
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0016() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.setFileConnection("newFileName");
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,462 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class SetHidden extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
if (isTestValid("test0012")) test0012();
if (isTestValid("test0013")) test0013();
}
/**
* Tests setHidden() on a file
*/
public void test0001() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
addOperationDesc("setting hidden attribute to " + !isHidden);
conn.setHidden(!isHidden);
boolean isHidden2 = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden2);
passed = isHidden2 != isHidden;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setHidden() on a file", passed);
}
/**
* Tests setHidden() on a directory
*/
public void test0002() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
addOperationDesc("setting hidden attribute to " + !isHidden);
conn.setHidden(!isHidden);
boolean isHidden2 = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden2);
passed = isHidden2 != isHidden;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setHidden() on a directory", passed);
}
/**
* Tests setHidden() on a file (hidden attribute is NOT supported by filesystem)
*/
public void test0003() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
addOperationDesc("setting hidden attribute to true");
conn.setHidden(true);
boolean isHidden2 = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden2);
passed = isHidden == false && isHidden2 == false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setHidden() on a file (hidden attribute is NOT supported by filesystem)", passed);
}
/**
* Tests setHidden() on a directory (hidden attribute is NOT supported by filesystem)
*/
public void test0004() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
boolean isHidden = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
addOperationDesc("setting hidden attribute to true");
conn.setHidden(true);
boolean isHidden2 = conn.isHidden();
addOperationDesc("isHidden() returned " + isHidden2);
passed = isHidden == false && isHidden2 == false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setHidden() on a directory (hidden attribute is NOT supported by filesystem)", passed);
}
/**
* ConnectionClosedException thrown if connection is closed
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("closing connection");
conn.close();
try {
conn.setHidden(true);
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if connection is closed", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.READ mode
*/
public void test0006() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ);
try {
try {
conn.setHidden(true);
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests setHidden() in Connector.WRITE mode
*/
public void test0007() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = null;
FileConnection conn2 = null;
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn2.getURL());
ensureFileExists(conn2);
boolean isHidden = conn2.isHidden();
addOperationDesc("isHidden() returned " + isHidden);
addOperationDesc("setting hidden attribute to " + !isHidden);
conn.setHidden(!isHidden);
boolean isHidden2 = conn2.isHidden();
addOperationDesc("isHidden() returned " + isHidden2);
passed = true;
} finally {
if (conn != null) conn.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setHidden() in Connector.WRITE mode", passed);
}
/**
* IOException thrown for a non-existent file
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setHidden(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setHidden throws IOException for a non-existent file", passed);
}
/**
* IOException thrown for a non-existent file (hidden attribute is NOT supported by filesystem)
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setHidden(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setHidden throws IOException for a non-existent file (hidden attribute is NOT supported by filesystem)", passed);
}
/**
* IOException thrown for a non-existent directory
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setHidden(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setHidden throws IOException for a non-existent directory", passed);
}
/**
* IOException thrown for a non-existent directory (hidden attribute is NOT supported by filesystem)
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setHidden(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setHidden throws IOException for a non-existent directory (hidden attribute is NOT supported by filesystem)", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0012() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.setHidden(false);
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0013() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.setHidden(false);
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,462 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class SetReadable extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
if (isTestValid("test0012")) test0012();
if (isTestValid("test0013")) test0013();
}
/**
* Tests setReadable() on a file
*/
public void test0001() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
addOperationDesc("setting readable attribute to " + !canRead);
conn.setReadable(!canRead);
boolean canRead2 = conn.canRead();
addOperationDesc("canRead() returned " + canRead2);
passed = canRead2 != canRead;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setReadable() on a file", passed);
}
/**
* Tests setReadable() on a directory
*/
public void test0002() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
addOperationDesc("setting readable attribute to " + !canRead);
conn.setReadable(!canRead);
boolean canRead2 = conn.canRead();
addOperationDesc("canRead() returned " + canRead2);
passed = canRead2 != canRead;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setReadable() on a directory", passed);
}
/**
* Tests setReadable() on a file (readable attribute is NOT supported by filesystem)
*/
public void test0003() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
addOperationDesc("setting readable attribute to false");
conn.setReadable(false);
boolean canRead2 = conn.canRead();
addOperationDesc("canRead() returned " + canRead2);
passed = canRead == true && canRead2 == true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setReadable() on a file (readable attribute is NOT supported by filesystem)", passed);
}
/**
* Tests setReadable() on a directory (readable attribute is NOT supported by filesystem)
*/
public void test0004() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
boolean canRead = conn.canRead();
addOperationDesc("canRead() returned " + canRead);
addOperationDesc("setting readable attribute to false");
conn.setReadable(false);
boolean canRead2 = conn.canRead();
addOperationDesc("canRead() returned " + canRead2);
passed = canRead == true && canRead2 == true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setReadable() on a directory (readable attribute is NOT supported by filesystem)", passed);
}
/**
* ConnectionClosedException thrown if connection is closed
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("closing connection");
conn.close();
try {
conn.setReadable(true);
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if connection is closed", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.READ mode
*/
public void test0006() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ);
try {
try {
conn.setReadable(true);
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests setReadable() in Connector.WRITE mode
*/
public void test0007() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = null;
FileConnection conn2 = null;
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn2.getURL());
ensureFileExists(conn2);
boolean canRead = conn2.canRead();
addOperationDesc("canRead() returned " + canRead);
addOperationDesc("setting readable attribute to " + !canRead);
conn.setReadable(!canRead);
boolean canRead2 = conn2.canRead();
addOperationDesc("canRead() returned " + canRead2);
passed = true;
} finally {
if (conn != null) conn.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setReadable() in Connector.WRITE mode", passed);
}
/**
* IOException thrown for a non-existent file
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setReadable(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setReadable() throws IOException for a non-existent file", passed);
}
/**
* IOException thrown for a non-existent file (readable attribute is NOT supported by filesystem)
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setReadable(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setReadable throws IOException for a non-existent file (readable attribute is NOT supported by filesystem)", passed);
}
/**
* IOException thrown for a non-existent directory
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setReadable(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setReadable throws IOException for a non-existent directory", passed);
}
/**
* IOException thrown for a non-existent directory (readable attribute is NOT supported by filesystem)
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setReadable(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setReadable throws IOException for a non-existent directory (readable attribute is NOT supported by filesystem)", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0012() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.setReadable(true);
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0013() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.setReadable(true);
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,462 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class SetWritable extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
if (isTestValid("test0012")) test0012();
if (isTestValid("test0013")) test0013();
}
/**
* Tests setWritable() on a file
*/
public void test0001() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
addOperationDesc("setting writable attribute to " + !canWrite);
conn.setWritable(!canWrite);
boolean canWrite2 = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite2);
passed = canWrite2 != canWrite;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setWritable() on a file", passed);
}
/**
* Tests setWritable() on a directory
*/
public void test0002() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
addOperationDesc("setting writable attribute to " + !canWrite);
conn.setWritable(!canWrite);
boolean canWrite2 = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite2);
passed = canWrite2 != canWrite;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setWritable() on a directory", passed);
}
/**
* Tests setWritable() on a file (writable attribute is NOT supported by filesystem)
*/
public void test0003() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
addOperationDesc("setting writable attribute to false");
conn.setWritable(false);
boolean canWrite2 = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite2);
passed = canWrite == true && canWrite2 == true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setWritable() on a file (writable attribute is NOT supported by filesystem)", passed);
}
/**
* Tests setWritable() on a directory (writable attribute is NOT supported by filesystem)
*/
public void test0004() {
boolean passed = false;
FileConnection conn = null;
try {
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
boolean canWrite = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
addOperationDesc("setting writable attribute to false");
conn.setWritable(false);
boolean canWrite2 = conn.canWrite();
addOperationDesc("canWrite() returned " + canWrite2);
passed = canWrite == true && canWrite2 == true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setWritable() on a directory (writable attribute is NOT supported by filesystem)", passed);
}
/**
* ConnectionClosedException thrown if connection is closed
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("closing connection");
conn.close();
try {
conn.setWritable(true);
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if connection is closed", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.READ mode
*/
public void test0006() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ);
try {
try {
conn.setWritable(true);
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests setWritable() in Connector.WRITE mode
*/
public void test0007() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = null;
FileConnection conn2 = null;
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn2.getURL());
ensureFileExists(conn2);
boolean canWrite = conn2.canWrite();
addOperationDesc("canWrite() returned " + canWrite);
addOperationDesc("setting writable attribute to " + !canWrite);
conn.setWritable(!canWrite);
boolean canWrite2 = conn2.canWrite();
addOperationDesc("canWrite() returned " + canWrite2);
passed = true;
} finally {
if (conn != null) conn.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests setWritable() in Connector.WRITE mode", passed);
}
/**
* IOException thrown for a non-existent file
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setWritable(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setWritable throws IOException for a non-existent file", passed);
}
/**
* IOException thrown for a non-existent file (writable attribute is NOT supported by filesystem)
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setWritable(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setWritable throws IOException for a non-existent file (writable attribute is NOT supported by filesystem)", passed);
}
/**
* IOException thrown for a non-existent directory
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setWritable(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setWritable throws IOException for a non-existent directory", passed);
}
/**
* IOException thrown for a non-existent directory (writable attribute is NOT supported by filesystem)
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Deleting directory: " + conn.getURL());
ensureNotExists(conn);
try {
conn.setWritable(true);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("setWritable throws IOException for a non-existent directory (writable attribute is NOT supported by filesystem)", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0012() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.setWritable(true);
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0013() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.setWritable(false);
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,260 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class TotalSize extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
}
/**
* Tests totalSize()
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
long totalSize = conn.totalSize();
addOperationDesc("totalSize() returned " + totalSize);
passed = totalSize > 0;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests totalSize()", passed);
}
/**
* Tests totalSize() on two different connections on the same root volume
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
long totalSize1 = conn1.totalSize();
long totalSize2 = conn2.totalSize();
addOperationDesc("totalSize() returned " + totalSize1 + " for " + conn1.getURL());
addOperationDesc("totalSize() returned " + totalSize2 + " for " + conn2.getURL());
passed = totalSize1 == totalSize2;
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests totalSize() on two different connections on the same root volume", passed);
}
/**
* Tests totalSize() as the sum of usedSize() and availableSize()
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
long totalSize = conn.totalSize();
addOperationDesc("totalSize()="+totalSize);
long totalSize2 = conn.availableSize() + conn.usedSize();
addOperationDesc("availableSize()+usedSize()="+totalSize2);
passed = totalSize == totalSize2;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests totalSize() as the sum of usedSize() and availableSize()", passed);
}
/**
* ConnectionClosedException thrown if invoked on a closed connection
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
conn.close();
try {
conn.totalSize();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests totalSize() on a closed connection", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0005() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
conn.totalSize();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests totalSize() in Connector.READ mode
*/
public void test0006() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
long totalSize = conn.totalSize();
addOperationDesc("totalSize() call returned " + totalSize);
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests totalSize() in Connector.READ mode", passed);
}
/**
* Tests totalSize() on a non-existent file system
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
long totalSize = conn.totalSize();
addOperationDesc("totalSize() call returned " + totalSize);
passed = totalSize==-1;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests totalSize() on a non-existent file system", passed);
}
/**
* Tests totalSize() on a non-existent host
*/
public void test0008() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc(
"Opened connection on a non existent host: " + conn.getURL());
try {
long totalSize = conn.totalSize();
addOperationDesc("totalSize() call returned " + totalSize);
passed = totalSize == -1;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests totalSize() on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,399 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class Truncate extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
if (isTestValid("test0008")) test0008();
if (isTestValid("test0009")) test0009();
if (isTestValid("test0010")) test0010();
if (isTestValid("test0011")) test0011();
}
/**
* Tests truncate()
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Writing 8 bytes");
os = conn.openOutputStream();
os.write(new byte[8]);
os.close();
os = null;
addOperationDesc("Truncating at byte 1");
conn.truncate(1);
long fileSize = conn.fileSize();
addOperationDesc("fileSize() returned " + fileSize);
passed = fileSize==1;
} finally {
if (os != null) os.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests truncate()", passed);
}
/**
* Tests truncate() where byteOffset is greater than the current end of file
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Writing 8 bytes");
os = conn.openOutputStream();
os.write(new byte[8]);
os.close();
os = null;
addOperationDesc("Truncating at byte 10");
conn.truncate(10);
long fileSize = conn.fileSize();
addOperationDesc("fileSize() returned " + fileSize);
passed = fileSize==8;
} finally {
if (os != null) os.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests truncate() where byteOffset is greater than the current end of file", passed);
}
/**
* IOException thrown if invoked on a directory
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
try {
conn.truncate(0);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException thrown if invoked on a directory", passed);
}
/**
* IOException thrown if the file does not exist
*/
public void test0004() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
try {
conn.truncate(0);
addOperationDesc("No IOException thrown");
passed = false;
} catch (IOException e) {
addOperationDesc("Expected IOException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests truncate()", passed);
}
/**
* ConnectionClosedException thrown if connection is closed
*/
public void test0005() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
conn.close();
try {
conn.truncate(0);
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("ConnectionClosedException thrown if connection is closed", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.READ mode
*/
public void test0006() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
try {
conn.truncate(0);
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* IllegalArgumentException thrown if byteOffset is negative
*/
public void test0007() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
try {
try {
conn.truncate(-1);
addOperationDesc("No IllegalArgumentException thrown");
passed = false;
} catch (IllegalArgumentException e) {
passed = true;
addOperationDesc("Expected IllegalArgumentException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests truncate() in Connector.WRITE mode
*/
public void test0008() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = null;
FileConnection conn2 = null;
try {
conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn2);
addOperationDesc("Creating file");
conn.create();
boolean exists = conn2.exists();
addOperationDesc("exists() returned " + exists);
passed = exists==true;
} finally {
if (conn != null) conn.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests truncate() in Connector.WRITE mode", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent file system
*/
public void test0009() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.truncate(0);
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent file system", passed);
}
/**
* IOException or SecurityException thrown if connection is opened on a non-existent host
*/
public void test0010() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
try {
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn!=null) {
conn.truncate(0);
addOperationDesc("No IOException thrown");
passed = false;
}
} catch (IOException e) {
passed = true;
addOperationDesc("Expected IOException thrown");
} finally {
if (conn!=null) conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IOException or SecurityException thrown if connection is opened on a non-existent host", passed);
}
/**
* Tests if a file is truncated properly even if an open outputstream is not explicitly flushed by the user
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Writing 8 bytes");
os = conn.openOutputStream();
os.write(new byte[8]);
addOperationDesc("Truncating at byte 7");
conn.truncate(7);
long fileSize = conn.fileSize();
addOperationDesc("fileSize() returned " + fileSize);
passed = fileSize==7;
} finally {
if (os != null) os.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests if a file is truncated properly even if an open outputstream is not explicitly flushed by the user", passed);
}
}

Просмотреть файл

@ -0,0 +1,253 @@
package com.ibm.tck.javax.microedition.io.file.FileConnection;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.ConnectionClosedException;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class UsedSize extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
if (isTestValid("test0002")) test0002();
if (isTestValid("test0003")) test0003();
if (isTestValid("test0004")) test0004();
if (isTestValid("test0005")) test0005();
if (isTestValid("test0006")) test0006();
if (isTestValid("test0007")) test0007();
}
/**
* Tests usedSize()
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
long usedSize = conn.usedSize();
addOperationDesc("first usedSize() call returned " + usedSize);
int incrementSize = 4096;
addOperationDesc("writing " + incrementSize + " bytes to disk");
os = conn.openOutputStream();
os.write(new byte[incrementSize]);
os.close();
os = null;
long usedSize2 = conn.usedSize();
addOperationDesc("second usedSize() call returned " + usedSize2 + " (should be more than first call)");
passed = usedSize2>usedSize;
} finally {
if (os != null) os.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests usedSize()", passed);
}
/**
* Tests usedSize() on two different connections on the same root volume
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn1 = null;
FileConnection conn2 = null;
try {
conn1 = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
conn2 = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
long totalSize1 = conn1.totalSize();
long totalSize2 = conn2.totalSize();
addOperationDesc("usedSize() returned " + totalSize1 + " for " + conn1.getURL());
addOperationDesc("usedSize() returned " + totalSize2 + " for " + conn2.getURL());
passed = totalSize1 == totalSize2;
} finally {
if (conn1 != null) conn1.close();
if (conn2 != null) conn2.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests usedSize() on two different connections on the same root volume", passed);
}
/**
* ConnectionClosedException thrown if invoked on a closed connection
*/
public void test0003() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
conn.close();
try {
conn.usedSize();
addOperationDesc("No ConnectionClosedException thrown");
passed = false;
} catch (ConnectionClosedException e) {
addOperationDesc("Expected ConnectionClosedException thrown");
passed = true;
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests usedSize() on a closed connection", passed);
}
/**
* IllegalModeException thrown for connections opened in Connector.WRITE mode
*/
public void test0004() {
boolean passed = false;
try {
addOperationDesc("Opening connection in WRITE mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.WRITE);
try {
try {
conn.usedSize();
addOperationDesc("No IllegalModeException thrown");
passed = false;
} catch (IllegalModeException e) {
passed = true;
addOperationDesc("Expected IllegalModeException thrown");
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("IllegalModeException thrown for connections opened in Connector.WRITE mode", passed);
}
/**
* Tests usedSize() in Connector.READ mode
*/
public void test0005() {
boolean passed = false;
try {
addOperationDesc("Opening connection in READ mode");
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
try {
long totalSize = conn.usedSize();
addOperationDesc("usedSize() call returned " + totalSize);
passed = true;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests usedSize() in Connector.READ mode", passed);
}
/**
* Tests usedSize() on a non-existent file system
*/
public void test0006() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent file system: " + conn.getURL());
try {
long usedSize = conn.usedSize();
addOperationDesc("usedSize() call returned " + usedSize);
passed = usedSize==-1;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests usedSize() on a non-existent file system", passed);
}
/**
* Tests usedSize() on a non-existent host
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = null;
try {
String possibleNonExistentFilesystem ="TCKBogusHost/TCKFileSystem/";
conn = (FileConnection)Connector.open("file://"+possibleNonExistentFilesystem+"test", Connector.READ_WRITE);
} catch (IOException ioe) {
addOperationDesc("Expected IOException thrown");
passed = true;
} catch (SecurityException e) {
passed = true;
addOperationDesc("Expected SecurityException thrown");
}
if (conn != null) {
addOperationDesc("Opened connection on a non existent host: " + conn.getURL());
try {
long usedSize = conn.usedSize();
addOperationDesc("usedSize() call returned " + usedSize);
passed = usedSize == -1;
} finally {
conn.close();
}
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests usedSize() on a non-existent host", passed);
}
}

Просмотреть файл

@ -0,0 +1,17 @@
package com.ibm.tck.javax.microedition.io.file.FileSystemListener;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class RootChanged extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
}
}

Просмотреть файл

@ -0,0 +1,90 @@
package com.ibm.tck.javax.microedition.io.file.FileSystemRegistry;
import javax.microedition.io.file.FileSystemListener;
import javax.microedition.io.file.FileSystemRegistry;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class AddFileSystemListener extends TestCaseWithLog {
private static int newState = -1;
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
// if (isTestValid("test0001")) test0001();
System.out.println("TODO: FileSystemRegistry.AddFileSystemListener tests");
return;
}
/*
* Tests that a registered FileSystemListener receives notification of root changes
*/
public void test0001() {
interactiveMessage("Remove media from a removable drive");
FileSystemListener listener = new FileSystemListener() {
public void rootChanged(int state, String rootName) {
if (state == FileSystemListener.ROOT_ADDED)
log("root added: " + rootName);
if (state == FileSystemListener.ROOT_REMOVED)
log("root removed: " + rootName);
newState = state;
}
};
boolean addResult = FileSystemRegistry.addFileSystemListener(listener);
if (!addResult) {
addOperationDesc("addFileSystemListener() returned false (expected true)");
assertTrueWithLog("Tests that a registered FileSystemListener receives notification of root changes", false);
return;
}
newState = -1;
interactiveMessage("Insert media into a removable drive");
while(newState==-1) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
if (newState != FileSystemListener.ROOT_ADDED) {
addOperationDesc("listener was not notified of media change");
assertTrueWithLog("Tests that a registered FileSystemListener receives notification of root changes", false);
return;
}
newState = -1;
interactiveMessage("Remove media from a removable drive");
while(newState==-1) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
if (newState != FileSystemListener.ROOT_REMOVED) {
addOperationDesc("listener was not notified of media change");
assertTrueWithLog("Tests that a registered FileSystemListener receives notification of root changes", false);
return;
}
newState = -1;
interactiveMessage("Insert media into a removable drive");
while(newState==-1) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
if (newState != FileSystemListener.ROOT_ADDED) {
addOperationDesc("listener was not notified of media change");
assertTrueWithLog("Tests that a registered FileSystemListener receives notification of root changes", false);
return;
}
assertTrueWithLog("Tests that a registered FileSystemListener receives notification of root changes", true);
}
}

Просмотреть файл

@ -0,0 +1,162 @@
package com.ibm.tck.javax.microedition.io.file.FileSystemRegistry;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import javax.microedition.io.file.FileSystemListener;
import javax.microedition.io.file.FileSystemRegistry;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class ListRoots extends TestCaseWithLog {
private static int newState = -1;
private static String changedRoot = null;
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
// if (isTestValid("test0001")) test0001();
// if (isTestValid("test0002")) test0002();
System.out.println("TODO: FileSystemRegistry tests");
return;
}
/*
* Tests listRoots()
*/
public void test0001() {
Enumeration e = FileSystemRegistry.listRoots();
if (e==null) {
addOperationDesc("Enumeration was null");
assertTrueWithLog("Tests listRoots()", false);
return;
} else {
addOperationDesc("listRoots() returned:");
int i= 0;
while(e.hasMoreElements()) {
i++;
String root = (String)e.nextElement();
addOperationDesc(i + ". " + root);
if (root==null) {
addOperationDesc("Root was null");
assertTrueWithLog("Tests listRoots()", false);
return;
}
if (!root.endsWith("/")) {
addOperationDesc("Root does not end with slash: " + root);
assertTrueWithLog("Tests listRoots()", false);
return;
}
}
}
addOperationDesc("");
boolean passed = false;
if (!e.hasMoreElements()) {
try {
e.nextElement();
addOperationDesc("NoSuchElementException expected");
passed = false;
} catch (NoSuchElementException ex) {
addOperationDesc("NoSuchElementException thrown as expected");
passed = true;
}
}
assertTrueWithLog("Tests listRoots()", passed);
}
/*
* Tests that listRoots() changes when roots are mounted or unmounted
*/
public void test0002() {
interactiveMessage("Remove media from a removable drive");
FileSystemListener listener = new FileSystemListener() {
public void rootChanged(int state, String rootName) {
if (state == FileSystemListener.ROOT_ADDED)
log("root added: " + rootName);
if (state == FileSystemListener.ROOT_REMOVED)
log("root removed: " + rootName);
newState = state;
changedRoot = rootName;
}
};
FileSystemRegistry.addFileSystemListener(listener);
newState = -1;
interactiveMessage("Insert media into a removable drive");
while(newState==-1) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
if (newState != FileSystemListener.ROOT_ADDED) {
addOperationDesc("listener was not notified of media change");
assertTrueWithLog("Tests that listRoots() changes when roots are mounted or unmounted", false);
return;
}
if (!containsRoot(FileSystemRegistry.listRoots(), changedRoot)) {
addOperationDesc("root was not added to listRoots()");
assertTrueWithLog("Tests that listRoots() changes when roots are mounted or unmounted", false);
return;
}
newState = -1;
interactiveMessage("Remove media from a removable drive");
while(newState==-1) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
if (newState != FileSystemListener.ROOT_REMOVED) {
addOperationDesc("listener was not notified of media change");
assertTrueWithLog("Tests that listRoots() changes when roots are mounted or unmounted", false);
return;
}
if (containsRoot(FileSystemRegistry.listRoots(), changedRoot)) {
addOperationDesc("root was not removed to listRoots()");
assertTrueWithLog("Tests that listRoots() changes when roots are mounted or unmounted", false);
return;
}
newState = -1;
interactiveMessage("Insert media into a removable drive");
while(newState==-1) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
if (newState != FileSystemListener.ROOT_ADDED) {
addOperationDesc("listener was not notified of media change");
assertTrueWithLog("Tests that listRoots() changes when roots are mounted or unmounted", false);
return;
}
if (!containsRoot(FileSystemRegistry.listRoots(), changedRoot)) {
addOperationDesc("root was not added to listRoots()");
assertTrueWithLog("Tests that listRoots() changes when roots are mounted or unmounted", false);
return;
}
assertTrueWithLog("Tests that listRoots() changes when roots are mounted or unmounted", true);
}
private static boolean containsRoot(Enumeration e, String rootName) {
while(e.hasMoreElements()) {
String r = (String)e.nextElement();
if (r.equals(rootName)) {
return true;
}
}
return false;
}
}

Просмотреть файл

@ -0,0 +1,81 @@
package com.ibm.tck.javax.microedition.io.file.FileSystemRegistry;
import javax.microedition.io.file.FileSystemListener;
import javax.microedition.io.file.FileSystemRegistry;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class RemoveFileSystemListener extends TestCaseWithLog {
private static int newState = -1;
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
// if (isTestValid("test0001")) test0001();
System.out.println("TODO: FileSystemRegistry.RemoveFileSystemListener tests");
return;
}
/*
* Tests that a reregistered FileSystemListener does not receive notification of root changes
*/
public void test0001() {
FileSystemListener listener = new FileSystemListener() {
public void rootChanged(int state, String rootName) {
if (state == FileSystemListener.ROOT_ADDED)
log("root added: " + rootName);
if (state == FileSystemListener.ROOT_REMOVED)
log("root removed: " + rootName);
newState = state;
}
};
boolean result = FileSystemRegistry.addFileSystemListener(listener);
if (!result) {
addOperationDesc("addFileSystemListener() returned false (expected true)");
assertTrueWithLog("Tests that a reregistered FileSystemListener does not receive notification of root changes", false);
return;
}
long startTime = System.currentTimeMillis();
newState = -1;
interactiveMessage("Insert or remove media from a removable drive");
while(newState==-1) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
long elapsedTime = System.currentTimeMillis() - startTime;
result = FileSystemRegistry.removeFileSystemListener(listener);
if (!result) {
addOperationDesc("removeFileSystemListener() returned false (expected true)");
assertTrueWithLog("Tests that a reregistered FileSystemListener does not receive notification of root changes", false);
return;
}
newState = -1;
interactiveMessage("Insert or remove media from a removable drive");
startTime = System.currentTimeMillis();
while((System.currentTimeMillis()-startTime)<2*elapsedTime) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
if (newState != -1) {
addOperationDesc("deregistered listener was notified of media change");
assertTrueWithLog("Tests that a reregistered FileSystemListener does not receive notification of root changes", false);
return;
}
assertTrueWithLog("Tests that a reregistered FileSystemListener does not receive notification of root changes", true);
}
}

Просмотреть файл

@ -0,0 +1,28 @@
package com.ibm.tck.javax.microedition.io.file.IllegalModeException;
import javax.microedition.io.file.IllegalModeException;
import com.ibm.tck.javax.microedition.io.file.support.TestCaseWithLog;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class Init extends TestCaseWithLog {
/**
* @see com.ibm.tck.client.TestCase#runTests()
*/
public void runTests() {
if (isTestValid("test0001")) test0001();
}
/**
* Tests that a message that is set can be retrieved
*/
public void test0001() {
IllegalModeException e = new IllegalModeException("foo");
assertTrueWithLog("Tests that a message that is set can be retrieved", "foo".equals(e.getMessage()));
}
}

Просмотреть файл

@ -0,0 +1,115 @@
package com.ibm.tck.javax.microedition.io.file.support;
import java.io.IOException;
import java.util.Enumeration;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import com.ibm.tck.client.TestCase;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public abstract class TestCaseWithLog extends TestCase {
private StringBuffer operationTrace = new StringBuffer();
private String testPath = null;
protected String getTestPath() {
if (testPath == null) {
testPath = (String)getOptions().get("FilesystemTestPath");
}
return testPath;
}
protected void ensureFileExists(FileConnection conn) throws IOException {
if (conn.exists()) {
// if the file already exists, delete it to ensure zero length when created again
recursiveDelete(conn);
}
try {
conn.create();
} catch (Exception e) {
throw new IOException("could not create file <" + conn.getURL() + "> (" + e.getMessage() + ")");
}
}
protected void ensureDirExists(FileConnection conn) throws IOException {
if (conn.exists()) {
// if the dir already exists, delete it to ensure zero length when created again
recursiveDelete(conn);
}
try {
conn.mkdir();
} catch (Exception e) {
throw new IOException("could not create directory <" + conn.getURL() + "> (" + e.getMessage() + ")");
}
}
protected void ensureNotExists(FileConnection conn) throws IOException {
if (conn.exists()) {
recursiveDelete(conn);
}
}
private void recursiveDelete(FileConnection conn) throws IOException {
try {
if (conn.isDirectory()) {
for (Enumeration e=conn.list("*", true); e.hasMoreElements(); ) {
String fileName = (String)e.nextElement();
FileConnection childConn = null;
try {
childConn = (FileConnection)Connector.open(conn.getURL() + fileName);
recursiveDelete(childConn);
} finally {
if (childConn != null) {
childConn.close();
}
}
}
}
conn.setWritable(true);
conn.delete();
} catch (IOException e) {
throw new IOException("could not delete <" + conn.getURL() + "> (" + e.getMessage() + ")");
}
}
protected void logUnexpectedExceptionDesc(Exception e) {
logTrace();
StringBuffer message = new StringBuffer(80);
message.append("Unexpected exception: (");
message.append(e.getClass().getName());
message.append(") ");
message.append(e.getMessage());
log(message.toString());
}
public void assertTrueWithLog(String message, boolean passed) {
logTrace();
assertTrue(message, passed);
}
protected void addOperationDesc(String comment) {
StringBuffer buffer = new StringBuffer(comment.length() + 3);
buffer.append(" ");
buffer.append(comment);
buffer.append('\n');
operationTrace.append(buffer.toString());
}
private void logTrace() {
if (operationTrace.length() != 0) {
log("Operation trace:");
log(operationTrace.toString());
// clear the trace.
operationTrace.delete(0, operationTrace.length());
}
}
}

Просмотреть файл

@ -0,0 +1,130 @@
package com.ibm.tck.javax.microedition.io.file.support;
import java.io.ByteArrayOutputStream;
/*
* Licensed Materials - Property of IBM,
* (c) Copyright IBM Corp. 2003 All Rights Reserved
*/
public class URLSupport {
public static String getPathWithHost(String testpath) {
int index = testpath.indexOf('/');
if (index!=0)
return testpath;
else
return "localhost" + testpath;
}
public static String getPathWithoutHost(String testpath) {
int index = testpath.indexOf('/');
if (index!=0) {
//incase the testpath is in this form: <host>/<root>/<path>/
testpath = testpath.substring(index,testpath.length());
}
return testpath;
}
/**
* Decode the <code>url</code>
*/
public static String getUnescapedForm(String url) {
return decode(url);
}
/**
* First decode, then encode the <code>url</code>
* this needed to coever all the cases,
* where the <code>url</code> might be in escaped, or unescaped form,
* and needs to be always returned in escaped form.
*/
public static String getEscapedForm(String url) {
final String digits = "0123456789ABCDEF";
return encode(decode(url), digits);
}
/**
* First decode, then encode the <code>url</code>
* this needed to coever all the cases,
* where the <code>url</code> might be in escaped, or unescaped form,
* and needs to be always returned in escaped form.
*/
public static String getAlternativeEscapedForm(String url) {
final String digits = "0123456789abcdef";
return encode(decode(url), digits);
}
/**
* All characters except for the following are escaped (converted into their
* hexadecimal value prepended by '%'):
* letters ('a'..'z', 'A'..'Z'),
* numbers ('0'..'9'),
* unreserved characters ('-', '_', '.', '!', '~', '*', '\'', '(', ')'), and
* reserved characters ('/', ':')
* <p>
* For example: '#' -> %23
*
* @return java.lang.String the string to be converted
* @param s java.lang.String the converted string
*/
private static String encode(String s, String digits) {
StringBuffer buf = new StringBuffer(s.length());
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if ((ch >= 'a' && ch <= 'z')
|| (ch >= 'A' && ch <= 'Z')
|| (ch >= '0' && ch <= '9')
|| "-_.!~*\'()//:".indexOf(ch) > -1)
buf.append(ch);
else {
byte[] bytes = new String(new char[] { ch }).getBytes();
for (int j = 0; j < bytes.length; j++) {
buf.append('%');
buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
buf.append(digits.charAt(bytes[j] & 0xf));
}
}
}
return buf.toString();
}
/**
* <p>
* '%' and two following hex digit characters are converted
* to the equivalent byte value.
* All other characters are passed through unmodified.
* <p>
* e.g. "ABC %24%25" -> "ABC $%"
*
* @param s java.lang.String The encoded string.
* @return java.lang.String The decoded version.
*/
private static String decode(String s) {
StringBuffer result = new StringBuffer(s.length());
ByteArrayOutputStream out = new ByteArrayOutputStream();
for (int i = 0; i < s.length();) {
char c = s.charAt(i);
if (c == '%') {
out.reset();
do {
if (i + 2 >= s.length())
throw new IllegalArgumentException("Incomplete % sequence at: " + i);
int d1 = Character.digit(s.charAt(i+1), 16);
int d2 = Character.digit(s.charAt(i+2), 16);
if (d1 == -1 || d2 == -1)
throw new IllegalArgumentException("Invalid % sequence (" + s.substring(i, i+3)+ ") at: " + String.valueOf(i));
out.write((byte)((d1 << 4) + d2));
i += 3;
} while (i < s.length() && s.charAt(i) == '%');
result.append(out.toString());
continue;
} else result.append(c);
i++;
}
return result.toString();
}
}

Просмотреть файл

@ -28,7 +28,7 @@ public class TestLauncher implements Testlet {
public void test(TestHarness th) {
try {
FileConnection file = (FileConnection)Connector.open("file:///test.jpg", Connector.READ_WRITE);
FileConnection file = (FileConnection)Connector.open("file:////test.jpg", Connector.READ_WRITE);
if (!file.exists()) {
file.create();
}

Просмотреть файл

@ -56,7 +56,7 @@ public class TestRandomAccessStream implements Testlet {
}
void cleanup() throws IOException {
FileConnection file = (FileConnection)Connector.open("file:///afile");
FileConnection file = (FileConnection)Connector.open("file:////afile");
file.delete();
file.close();
}

Просмотреть файл

@ -32,7 +32,7 @@ public class TestInputOutputStorage implements Testlet {
public void test(TestHarness th) {
try {
FileConnection file = (FileConnection)Connector.open("file:///prova");
FileConnection file = (FileConnection)Connector.open("file:////prova");
th.check(!file.exists());
file.create();

Просмотреть файл

@ -91,7 +91,7 @@ public class TestRecordStoreFileNatives implements Testlet, SuiteContainer {
th.fail("record store file could not be deleted: " + ex);
}
try {
final String RECORD_STORE_BASE_URL = "file:///RecordStore";
final String RECORD_STORE_BASE_URL = "file:////RecordStore";
FileConnection dir = (FileConnection)Connector.open(RECORD_STORE_BASE_URL + "/" + filenameBase);
dir.delete();

Просмотреть файл

@ -27,16 +27,20 @@ casper.test.begin("fs tests", 6, function(test) {
// by deleting and recreating the database between test runs. We may also
// want to move over the other tests that touch the fs.
casper
.start("http://localhost:8000/tests/fs/delete-fs.html")
.waitForText("DONE");
// Initialize a v1 database.
casper
.start("http://localhost:8000/tests/fs/init-fs-v1.html")
.thenOpen("http://localhost:8000/tests/fs/init-fs-v1.html")
.waitForText("DONE");
// Upgrade the database to the latest version and test its initial state.
casper
.thenOpen("http://localhost:8000/tests/fs/test-fs-init.html")
.waitForText("DONE", function() {
test.assertTextExists("DONE: 14 PASS, 0 FAIL", "test fs v1 upgrade/init");
test.assertTextExists("DONE: 30 pass, 0 fail", "test fs v1 upgrade/init");
});
// Run the unit tests against the upgraded database.
@ -59,7 +63,7 @@ casper.test.begin("fs tests", 6, function(test) {
casper
.thenOpen("http://localhost:8000/tests/fs/test-fs-init.html")
.waitForText("DONE", function() {
test.assertTextExists("DONE: 14 PASS, 0 FAIL", "test fs v2 upgrade/init");
test.assertTextExists("DONE: 30 pass, 0 fail", "test fs v2 upgrade/init");
});
// Run the unit tests against the upgraded database.
@ -82,7 +86,7 @@ casper.test.begin("fs tests", 6, function(test) {
casper
.thenOpen("http://localhost:8000/tests/fs/test-fs-populate.html")
.waitForText("DONE", function() {
test.assertTextExists("DONE: 218 PASS, 0 FAIL", "test fs v2 upgrade/populate");
test.assertTextExists("DONE: 234 pass, 0 fail", "test fs v2 upgrade/populate");
});
// Run the unit tests.

Просмотреть файл

@ -11,9 +11,7 @@ var log = function() {
document.body.textContent += s + "\n";
// Log it via console.log so it gets written to the test automation log.
// XXX Commented out because `make test` currently fails if the test log
// contains the text "FAIL", and this causes that text to appear in it.
// console.log(s);
console.log(s);
}
var passed = 0, failed = 0, then = performance.now();
@ -21,22 +19,20 @@ var passed = 0, failed = 0, then = performance.now();
function is(a, b, msg) {
if (a == b) {
++passed;
log("PASS " + msg);
log("pass " + msg);
} else {
++failed;
log("FAIL " + msg);
log("GOT: " + JSON.stringify(a));
log("EXPECTED: " + JSON.stringify(b));
log("fail " + msg + "; expected " + JSON.stringify(b) + ", got " + JSON.stringify(a));
}
}
function ok(a, msg) {
if (!!a) {
++passed;
log("PASS " + msg);
log("pass " + msg);
} else {
++failed;
log("FAIL " + msg);
log("fail " + msg);
}
}
@ -45,8 +41,8 @@ var tests = [];
function next() {
if (tests.length == 0) {
ok(true, "TESTS COMPLETED");
log("DONE: " + passed + " PASS, " + failed + " FAIL, " +
(Math.round(performance.now() - then)) + " TIME");
log("DONE: " + passed + " pass, " + failed + " fail, " +
(Math.round(performance.now() - then)) + " time");
} else {
var test = tests.shift();
test();
@ -57,23 +53,38 @@ function next() {
// We check that they all exist.
var initialPaths = [
"/",
"/MemoryCard",
"/Persistent",
"/Photos",
"/Phone",
"/Phone/_my_downloads",
"/Phone/_my_pictures",
"/Phone/_my_videos",
"/Phone/_my_recordings",
"/Private",
"/_main.ks",
];
// The initial files we expect to find in the filesystem, indexed by parent dir.
// We check that the directories have the files we expect to find in them.
// The keys are directory paths, while the values are filenames (with a slash
// appended to the names of directories).
var initialFilesByDir = {
"/": [
"MemoryCard/",
"Persistent/",
"Photos/",
"Phone/",
"Private/",
"_main.ks",
],
"/MemoryCard": [],
"/Persistent": [],
"/Photos": [],
"/Phone": [
"_my_downloads/",
"_my_pictures/",
"_my_videos/",
"_my_recordings/",
],
"/Private": [],
};
function testInit() {

Просмотреть файл

@ -58,7 +58,7 @@ public class ImageProcessingTest extends MIDlet {
client.receive(msg);
byte[] clientData = msg.getData();
FileConnection originalImage = (FileConnection)Connector.open("file:///test.jpg", Connector.READ_WRITE);
FileConnection originalImage = (FileConnection)Connector.open("file:////test.jpg", Connector.READ_WRITE);
if (!originalImage.exists()) {
originalImage.create();
}
@ -91,7 +91,7 @@ public class ImageProcessingTest extends MIDlet {
dataDecoder.getString(13);
dataDecoder.getInteger(2);
dataDecoder.getString(10);
String path = "file:///" + dataDecoder.getString(11);
String path = "file:////" + dataDecoder.getString(11);
if (!originalImage.exists()) {
System.out.println("FAIL - Original image has been deleted");

Просмотреть файл

@ -42,7 +42,7 @@ public class MediaImageTest extends MIDlet implements PlayerListener {
display = Display.getDisplay(this);
form = new Form("Test");
FileConnection file = (FileConnection)Connector.open("file:///test.jpg", Connector.READ_WRITE);
FileConnection file = (FileConnection)Connector.open("file:////test.jpg", Connector.READ_WRITE);
if (!file.exists()) {
file.create();
}
@ -51,7 +51,7 @@ public class MediaImageTest extends MIDlet implements PlayerListener {
os.write(read(is));
os.close();
player = Manager.createPlayer("file:///test.jpg");
player = Manager.createPlayer("file:////test.jpg");
player.addPlayerListener(this);

Просмотреть файл

@ -38,7 +38,7 @@ public class TestAudioPlayer implements Testlet, PlayerListener {
// Test player with file URL.
try {
String url = "file:///hello.wav";
String url = "file:////hello.wav";
FileConnection file = (FileConnection)Connector.open(url, Connector.READ_WRITE);
if (!file.exists()) {
file.create();

Просмотреть файл

@ -36,7 +36,7 @@ public class TestMediaImage implements Testlet, PlayerListener {
try {
Form form = new Form("Test");
FileConnection file = (FileConnection)Connector.open("file:///test.jpg", Connector.READ_WRITE);
FileConnection file = (FileConnection)Connector.open("file:////test.jpg", Connector.READ_WRITE);
if (!file.exists()) {
file.create();
}
@ -45,7 +45,7 @@ public class TestMediaImage implements Testlet, PlayerListener {
os.write(read(is));
os.close();
Player player = Manager.createPlayer("file:///test.jpg");
Player player = Manager.createPlayer("file:////test.jpg");
player.addPlayerListener(this);

Просмотреть файл

@ -91,7 +91,7 @@ public class FileUIMIDlet extends MIDlet {
dataDecoder.getStart(14);
dataDecoder.getString(10);
dataDecoder.getString(11);
String path = "file:///" + dataDecoder.getString(11);
String path = "file:////" + dataDecoder.getString(11);
dataDecoder.getBoolean();
dataDecoder.getInteger(7);
dataDecoder.getEnd(14);

Просмотреть файл

@ -43,7 +43,7 @@ public class TestNokiaImageProcessingInMultiThread implements Testlet {
public void run() {
try {
LocalMessageProtocolConnection client = (LocalMessageProtocolConnection)Connector.open("localmsg://" + PROTO_NAME);
FileConnection originalImage = (FileConnection)Connector.open("file:///" + this.name, Connector.READ_WRITE);
FileConnection originalImage = (FileConnection)Connector.open("file:////" + this.name, Connector.READ_WRITE);
if (!originalImage.exists()) {
originalImage.create();
}
@ -76,7 +76,7 @@ public class TestNokiaImageProcessingInMultiThread implements Testlet {
th.check(dataDecoder.getString(13), "Scale");
th.check(dataDecoder.getInteger(2), 42);
th.check(dataDecoder.getString(10), "Complete");
String path = "file:///" + dataDecoder.getString(11);
String path = "file:////" + dataDecoder.getString(11);
FileConnection file = (FileConnection)Connector.open(path);
th.check(file.exists(), "File exists");

Просмотреть файл

@ -63,7 +63,7 @@ public class TestNokiaImageProcessingServer implements Testlet {
public void testScaleImage(TestHarness th, int maxKb, int maxHres, int maxVres) throws IOException {
// Store an image in the fs
FileConnection originalImage = (FileConnection)Connector.open("file:///test.jpg", Connector.READ_WRITE);
FileConnection originalImage = (FileConnection)Connector.open("file:////test.jpg", Connector.READ_WRITE);
if (!originalImage.exists()) {
originalImage.create();
}
@ -106,7 +106,7 @@ public class TestNokiaImageProcessingServer implements Testlet {
th.check(dataDecoder.getString(13), "Scale");
th.check(dataDecoder.getInteger(2), 42);
th.check(dataDecoder.getString(10), "Complete");
String path = "file:///" + dataDecoder.getString(11);
String path = "file:////" + dataDecoder.getString(11);
FileConnection file = (FileConnection)Connector.open(path);
th.check(file.exists(), "File exists");