From d665f035636feafb9028cbfeb9385638d1650c49 Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Sun, 28 Dec 2014 19:58:58 -0800 Subject: [PATCH 01/18] add tests/runner from IBM TCK for JSR-075 FileConnection API --- LICENSE | 31 + .../com/ibm/tck/client/ClientConnection.java | 26 + .../ibm/tck/client/MIDPClientConnection.java | 80 + tests/com/ibm/tck/client/TCKMidlet.java | 43 + tests/com/ibm/tck/client/TestCase.java | 138 ++ tests/com/ibm/tck/client/TestRunner.java | 278 ++++ .../file/ConnectionClosedException/Init.java | 28 + .../io/file/FileConnection/AvailableSize.java | 257 ++++ .../io/file/FileConnection/CanRead.java | 477 ++++++ .../io/file/FileConnection/CanWrite.java | 476 ++++++ .../io/file/FileConnection/Create.java | 293 ++++ .../io/file/FileConnection/Delete.java | 457 ++++++ .../io/file/FileConnection/DirectorySize.java | 427 ++++++ .../io/file/FileConnection/Exists.java | 295 ++++ .../io/file/FileConnection/FileSize.java | 327 ++++ .../io/file/FileConnection/GetName.java | 383 +++++ .../io/file/FileConnection/GetPath.java | 263 ++++ .../io/file/FileConnection/GetURL.java | 417 +++++ .../io/file/FileConnection/IsDirectory.java | 302 ++++ .../io/file/FileConnection/IsHidden.java | 476 ++++++ .../io/file/FileConnection/LastModified.java | 336 ++++ .../io/file/FileConnection/List.java | 1363 +++++++++++++++++ .../io/file/FileConnection/Mkdir.java | 334 ++++ .../io/file/FileConnection/Open.java | 176 +++ .../FileConnection/OpenDataInputStream.java | 399 +++++ .../FileConnection/OpenDataOutputStream.java | 440 ++++++ .../file/FileConnection/OpenInputStream.java | 396 +++++ .../file/FileConnection/OpenOutputStream.java | 443 ++++++ .../FileConnection/OpenOutputStream_Long.java | 559 +++++++ .../file/FileConnection/PackageDiscovery.java | 28 + .../io/file/FileConnection/Rename.java | 805 ++++++++++ .../FileConnection/SetFileConnection.java | 547 +++++++ .../io/file/FileConnection/SetHidden.java | 462 ++++++ .../io/file/FileConnection/SetReadable.java | 462 ++++++ .../io/file/FileConnection/SetWritable.java | 462 ++++++ .../io/file/FileConnection/TotalSize.java | 260 ++++ .../io/file/FileConnection/Truncate.java | 399 +++++ .../io/file/FileConnection/UsedSize.java | 253 +++ .../file/FileSystemListener/RootChanged.java | 17 + .../AddFileSystemListener.java | 88 ++ .../io/file/FileSystemRegistry/ListRoots.java | 160 ++ .../RemoveFileSystemListener.java | 79 + .../io/file/IllegalModeException/Init.java | 28 + .../io/file/support/TestCaseWithLog.java | 115 ++ .../io/file/support/URLSupport.java | 130 ++ 45 files changed, 14215 insertions(+) create mode 100755 tests/com/ibm/tck/client/ClientConnection.java create mode 100755 tests/com/ibm/tck/client/MIDPClientConnection.java create mode 100755 tests/com/ibm/tck/client/TCKMidlet.java create mode 100755 tests/com/ibm/tck/client/TestCase.java create mode 100755 tests/com/ibm/tck/client/TestRunner.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/ConnectionClosedException/Init.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/AvailableSize.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/CanRead.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/CanWrite.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/Create.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/Delete.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/DirectorySize.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/Exists.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/FileSize.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/GetName.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/GetPath.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/GetURL.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/IsDirectory.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/IsHidden.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/LastModified.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/List.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/Mkdir.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/Open.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/OpenDataInputStream.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/OpenDataOutputStream.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/OpenInputStream.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/OpenOutputStream.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/OpenOutputStream_Long.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/PackageDiscovery.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/Rename.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/SetFileConnection.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/SetHidden.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/SetReadable.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/SetWritable.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/TotalSize.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/Truncate.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileConnection/UsedSize.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileSystemListener/RootChanged.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileSystemRegistry/AddFileSystemListener.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileSystemRegistry/ListRoots.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/FileSystemRegistry/RemoveFileSystemListener.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/IllegalModeException/Init.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/support/TestCaseWithLog.java create mode 100755 tests/com/ibm/tck/javax/microedition/io/file/support/URLSupport.java diff --git a/LICENSE b/LICENSE index 93b25f5f..2ba39ba5 100644 --- a/LICENSE +++ b/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 diff --git a/tests/com/ibm/tck/client/ClientConnection.java b/tests/com/ibm/tck/client/ClientConnection.java new file mode 100755 index 00000000..105e3172 --- /dev/null +++ b/tests/com/ibm/tck/client/ClientConnection.java @@ -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 + * url passed and send the entire byte array data + * 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); + +} diff --git a/tests/com/ibm/tck/client/MIDPClientConnection.java b/tests/com/ibm/tck/client/MIDPClientConnection.java new file mode 100755 index 00000000..5bd0fa52 --- /dev/null +++ b/tests/com/ibm/tck/client/MIDPClientConnection.java @@ -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(); + } + + } + +} diff --git a/tests/com/ibm/tck/client/TCKMidlet.java b/tests/com/ibm/tck/client/TCKMidlet.java new file mode 100755 index 00000000..47d14a0f --- /dev/null +++ b/tests/com/ibm/tck/client/TCKMidlet.java @@ -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. + *
+	 * 	new TestRunner(this);
+	 * 	notifyDestroyed();
+	 * 
+ * @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 { + } +} diff --git a/tests/com/ibm/tck/client/TestCase.java b/tests/com/ibm/tck/client/TestCase.java new file mode 100755 index 00000000..8e5675ba --- /dev/null +++ b/tests/com/ibm/tck/client/TestCase.java @@ -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. + *
+	 * 
+	 * 		if (isTestValid("test0001"))
+	 * 			test0001();
+	 * 		if (isTestValid("test0002"))
+	 * 			test0002();
+	 * 
+	 * 
+ * Each test then makes use of ONE (1) assertTrue(String, boolean) and + * the reports are sent back to the server using DataOutputStreams: + *
+	 * 
+	 * 		String  -> com.company.subpackage.test.TestClass#test0001
+	 * 		boolean -> pass or fail
+	 * 		String  -> testDescription
+	 * 		String  -> testLog
+	 * 		long	-> elapsedTime
+	 * 
+	 * 
+ * + * 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 isTestValid() + * 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 (true) or failed (false). + */ + 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 null. + */ + public final Hashtable getOptions() { + return runner.getOptions(); + } + + /** + * Answer an Object that is the MIDlet running the testcase. If the TestCase makes any modification + * to the MIDlet they should be undone before the TestCase finishes. + * + * @return an Object (or null) representing the MIDlet the TestCase is running in. + */ + public final Object getMidlet() { + return runner.getMidlet(); + } + +} diff --git a/tests/com/ibm/tck/client/TestRunner.java b/tests/com/ibm/tck/client/TestRunner.java new file mode 100755 index 00000000..1292b3f8 --- /dev/null +++ b/tests/com/ibm/tck/client/TestRunner.java @@ -0,0 +1,278 @@ +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.
+ * + * One difference is that if the TestRunner is invoked by the TCKMidlet, an object + * representing the MIDlet is set in the runner. Any TestCase can + * cast the result of getMidlet() 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 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; + 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"); + } + + private boolean loadTestResources() { + 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", "///"); + return true; + } + +} diff --git a/tests/com/ibm/tck/javax/microedition/io/file/ConnectionClosedException/Init.java b/tests/com/ibm/tck/javax/microedition/io/file/ConnectionClosedException/Init.java new file mode 100755 index 00000000..783c575a --- /dev/null +++ b/tests/com/ibm/tck/javax/microedition/io/file/ConnectionClosedException/Init.java @@ -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())); + } + +} diff --git a/tests/com/ibm/tck/javax/microedition/io/file/FileConnection/AvailableSize.java b/tests/com/ibm/tck/javax/microedition/io/file/FileConnection/AvailableSize.java new file mode 100755 index 00000000..9d5482e5 --- /dev/null +++ b/tests/com/ibm/tck/javax/microedition/io/file/FileConnection/AvailableSize.java @@ -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